UNPKG

@swimlane/ngx-charts

Version:

Declarative Charting Framework for Angular2 and beyond!

120 lines 5.02 kB
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core'; import { area } from 'd3-shape'; import { sortLinear, sortByTime, sortByDomain } from '../utils/sort'; var AreaSeriesComponent = (function () { function AreaSeriesComponent() { this.stacked = false; this.normalized = false; this.select = new EventEmitter(); } AreaSeriesComponent.prototype.ngOnChanges = function (changes) { this.update(); }; AreaSeriesComponent.prototype.update = function () { var _this = this; this.updateGradient(); var currentArea; var startingArea; var xProperty = function (d) { var label = d.name; return _this.xScale(label); }; if (this.stacked || this.normalized) { currentArea = area() .x(xProperty) .y0(function (d, i) { return _this.yScale(d.d0); }) .y1(function (d, i) { return _this.yScale(d.d1); }); startingArea = area() .x(xProperty) .y0(function (d) { return _this.yScale.range()[0]; }) .y1(function (d) { return _this.yScale.range()[0]; }); } else { currentArea = area() .x(xProperty) .y0(function () { return _this.yScale.range()[0]; }) .y1(function (d) { return _this.yScale(d.value); }); startingArea = area() .x(xProperty) .y0(function (d) { return _this.yScale.range()[0]; }) .y1(function (d) { return _this.yScale.range()[0]; }); } currentArea.curve(this.curve); startingArea.curve(this.curve); this.opacity = .8; var data = this.data.series; if (this.scaleType === 'linear') { data = sortLinear(data, 'name'); } else if (this.scaleType === 'time') { data = sortByTime(data, 'name'); } else { data = sortByDomain(data, 'name', 'asc', this.xScale.domain()); } this.path = currentArea(data); this.startingPath = startingArea(data); }; AreaSeriesComponent.prototype.updateGradient = function () { if (this.colors.scaleType === 'linear') { this.hasGradient = true; if (this.stacked || this.normalized) { var d0values = this.data.series.map(function (d) { return d.d0; }); var d1values = this.data.series.map(function (d) { return d.d1; }); var max = Math.max.apply(Math, d1values); var min = Math.min.apply(Math, d0values); this.gradientStops = this.colors.getLinearGradientStops(max, min); } else { var values = this.data.series.map(function (d) { return d.value; }); var max = Math.max.apply(Math, values); this.gradientStops = this.colors.getLinearGradientStops(max); } } else { this.hasGradient = false; this.gradientStops = undefined; } }; AreaSeriesComponent.prototype.isActive = function (entry) { if (!this.activeEntries) return false; var item = this.activeEntries.find(function (d) { return entry.name === d.name; }); return item !== undefined; }; AreaSeriesComponent.prototype.isInactive = function (entry) { if (!this.activeEntries || this.activeEntries.length === 0) return false; var item = this.activeEntries.find(function (d) { return entry.name === d.name; }); return item === undefined; }; return AreaSeriesComponent; }()); export { AreaSeriesComponent }; AreaSeriesComponent.decorators = [ { type: Component, args: [{ selector: 'g[ngx-charts-area-series]', template: "\n <svg:g ngx-charts-area\n class=\"area-series\"\n [data]=\"data\"\n [path]=\"path\"\n [fill]=\"colors.getColor(data.name)\"\n [stops]=\"gradientStops\"\n [startingPath]=\"startingPath\"\n [opacity]=\"opacity\"\n [gradient]=\"gradient || hasGradient\"\n [class.active]=\"isActive(data)\"\n [class.inactive]=\"isInactive(data)\"\n />\n ", changeDetection: ChangeDetectionStrategy.OnPush },] }, ]; /** @nocollapse */ AreaSeriesComponent.ctorParameters = function () { return []; }; AreaSeriesComponent.propDecorators = { 'data': [{ type: Input },], 'xScale': [{ type: Input },], 'yScale': [{ type: Input },], 'colors': [{ type: Input },], 'scaleType': [{ type: Input },], 'stacked': [{ type: Input },], 'normalized': [{ type: Input },], 'gradient': [{ type: Input },], 'curve': [{ type: Input },], 'activeEntries': [{ type: Input },], 'select': [{ type: Output },], }; //# sourceMappingURL=area-series.component.js.map