1 line
20 KiB
Plaintext
1 line
20 KiB
Plaintext
|
{"version":3,"file":"ng2-charts.mjs","sources":["../../../../libs/ng2-charts/src/lib/theme.service.ts","../../../../libs/ng2-charts/src/lib/base-chart.directive.ts","../../../../libs/ng2-charts/src/lib/base-colors.ts","../../../../libs/ng2-charts/src/lib/get-colors.ts","../../../../libs/ng2-charts/src/lib/ng-charts.module.ts","../../../../libs/ng2-charts/src/index.ts","../../../../libs/ng2-charts/src/ng2-charts.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\nimport { ChartConfiguration, ChartOptions } from 'chart.js';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ThemeService {\n private pColorschemesOptions?: ChartOptions;\n public colorschemesOptions: BehaviorSubject<ChartOptions | undefined> =\n new BehaviorSubject<ChartOptions | undefined>(undefined);\n\n setColorschemesOptions(options: ChartConfiguration['options']): void {\n this.pColorschemesOptions = options;\n this.colorschemesOptions.next(options);\n }\n\n getColorschemesOptions(): ChartConfiguration['options'] {\n return this.pColorschemesOptions;\n }\n}\n","import {\n Directive,\n ElementRef,\n EventEmitter,\n Input,\n NgZone,\n OnChanges,\n OnDestroy,\n Output,\n SimpleChanges,\n} from '@angular/core';\nimport {\n Chart,\n ChartConfiguration,\n ChartEvent,\n ChartType,\n DefaultDataPoint,\n Plugin,\n} from 'chart.js';\n\nimport { ThemeService } from './theme.service';\nimport { Subscription } from 'rxjs';\nimport { distinctUntilChanged } from 'rxjs/operators';\n\nimport { merge } from 'lodash-es';\n\n@Directive({\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: 'canvas[baseChart]',\n exportAs: 'base-chart',\n})\nexport class BaseChartDirective<\n TType extends ChartType = ChartType,\n TData = DefaultDataPoint<TType>,\n TLabel = unknown\n> implements OnDestroy, OnChanges\n{\n @Input() public type: ChartConfiguration<TType, TData, TLabel>['type'] =\n 'bar' as TType;\n @Input() public legend?: boolean;\n @Input() public data?: ChartConfiguration<TType, TData, TLabel>['data'];\n @Input() public options: ChartConfiguration<TType, TData, TLabel>['options'];\n @Input() public plugins: Plugin<TType>[] = [];\n\n @Input() public labels?: ChartConfiguration<\n TType,\n TData,\n TLabel\n >['data']['labels'];\n @Input() public datasets?: ChartConfiguration<\n TType,\n TData,\n TLabel\n >['data']['datasets'];\n\n @Output() public chartClick: EventEmitter<{\n event?: ChartEvent;\n active?: object[];\n }> = new EventEmitter();\n @Output() public chartHover: EventEmitter<{\n event: ChartEvent;\n active: object[];\n }> = new EventEmitter();\n\n public ctx: string;\n public chart?: Chart<TType, TData, TLabel>;\n\n private subs: Subscription[] = [];\n private themeOverrides: ChartConfiguration['options'] = {};\n\n public constructor(\n element: ElementRef,\n private zone: NgZone,\n private themeService: ThemeService\n ) {\n this.ctx = element.nativeElement.getContext('2d');\n this.subs.push(\n this.themeService.colorschemesOptions\n .pipe(distinctUntilChanged())\n .subscribe((r) => this.themeChanged(r))\n );\n }\n\n ngOnChanges(changes: SimpleChanges): void {\n const requireRender = ['type'];\n const propertyNames = Object.getOwnPropertyNames(changes);\n\n if (\n propertyNames.some((key) => requireRender.includes(key)) ||\n propertyNames.every((key) => changes[key].isFirstChange())\n ) {\n this.render();\n } else {\n const config = this.getChartConfiguration();\n\n // Using assign to avoid changing the original object reference\n if (this.chart) {\n Object.assign(this.chart.config.data, config.data);\n if (this.chart.config.plugins) {\n Object.assign(this.chart.config.plugins, config.plugins);\n }\n if (this.chart.config.options) {\n Object.assign(this.chart.config.options, config.options);\n }\n }\n\n this.update();\n }\n }\n\n public ng
|