import { Injectable } from '@angular/core' ; import { Organization } from "../../services/api-services/models/organization.class" ; import { Dataset } from "./models/dataset.class" ; import { DataPoint } from "../../services/api-services/models/analytics/data-point.interface" ; import { PieDataset } from "./models/pie-dataset.class" ; import { HistogramDataset } from "./models/histogram-dataset.class" ; import { WsColorService } from "../../services/ui-services/ws-color.service" ; @ Injectable ( ) export class WsChartService { constructor ( private colorService ) { } private getPieColorPalette ( length ) { let colors = this . colorService . getColorPaletteOfLength ( length ) ; return [ { backgroundColor : colors , hoverBackgroundColor : colors , } ] ; } public dataPointsToHistogram ( dataPoints , seriesName ) { let toReturn = new HistogramDataset ( ) ; for ( let dataPoint of dataPoints ) { toReturn . addDataPoint ( dataPoint , seriesName ) ; toReturn . addDataLabel ( dataPoint ) ; } return toReturn ; } public dataPointsToPie ( dataPoints ) { let toReturn = new PieDataset ( ) ; for ( let dataPoint of dataPoints ) { toReturn . addDataPoint ( dataPoint ) ; } toReturn . setChartColors ( this . getPieColorPalette ( dataPoints . length ) ) ; return toReturn ; } public getServiceDistributionFromOrganization ( organization ) { let datasetMap = { } ; let toReturn = [ ] ; for ( let key in datasetMap ) { toReturn . push ( datasetMap [ key ] ) ; } return toReturn ; } }