UNPKG

@swimlane/ngx-charts

Version:

Declarative Charting Framework for Angular2 and beyond!

161 lines 7.63 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var core_1 = require('@angular/core'); var d3_1 = require('../d3'); var base_chart_component_1 = require('../common/base-chart.component'); var view_dimensions_helper_1 = require('../common/view-dimensions.helper'); var color_helper_1 = require('../common/color.helper'); var HeatMapComponent = (function (_super) { __extends(HeatMapComponent, _super); function HeatMapComponent() { _super.apply(this, arguments); this.margin = [10, 20, 10, 20]; this.xAxisHeight = 0; this.yAxisWidth = 0; } HeatMapComponent.prototype.update = function () { var _this = this; _super.prototype.update.call(this); this.zone.run(function () { _this.dims = view_dimensions_helper_1.calculateViewDimensions({ width: _this.width, height: _this.height, margins: _this.margin, showXAxis: _this.xAxis, showYAxis: _this.yAxis, xAxisHeight: _this.xAxisHeight, yAxisWidth: _this.yAxisWidth, showXLabel: _this.showXAxisLabel, showYLabel: _this.showYAxisLabel, showLegend: _this.legend, legendType: 'linear' }); _this.formatDates(); _this.xDomain = _this.getXDomain(); _this.yDomain = _this.getYDomain(); _this.valueDomain = _this.getValueDomain(); _this.xScale = _this.getXScale(); _this.yScale = _this.getYScale(); _this.setColors(); _this.legendOptions = _this.getLegendOptions(); _this.transform = "translate(" + _this.dims.xOffset + " , " + _this.margin[0] + ")"; _this.rects = _this.getRects(); }); }; HeatMapComponent.prototype.getXDomain = function () { var domain = []; for (var _i = 0, _a = this.results; _i < _a.length; _i++) { var group = _a[_i]; if (!domain.includes(group.name)) { domain.push(group.name); } } return domain; }; HeatMapComponent.prototype.getYDomain = function () { var domain = []; for (var _i = 0, _a = this.results; _i < _a.length; _i++) { var group = _a[_i]; for (var _b = 0, _c = group.series; _b < _c.length; _b++) { var d = _c[_b]; if (!domain.includes(d.name)) { domain.push(d.name); } } } return domain; }; HeatMapComponent.prototype.getValueDomain = function () { var domain = []; for (var _i = 0, _a = this.results; _i < _a.length; _i++) { var group = _a[_i]; for (var _b = 0, _c = group.series; _b < _c.length; _b++) { var d = _c[_b]; if (!domain.includes(d.value)) { domain.push(d.value); } } } var min = Math.min.apply(Math, [0].concat(domain)); var max = Math.max.apply(Math, domain); return [min, max]; }; HeatMapComponent.prototype.getXScale = function () { return d3_1.default.scaleBand() .rangeRound([0, this.dims.width]) .paddingInner(0.1) .domain(this.xDomain); }; HeatMapComponent.prototype.getYScale = function () { return d3_1.default.scaleBand() .rangeRound([this.dims.height, 0]) .paddingInner(0.1) .domain(this.yDomain); }; HeatMapComponent.prototype.getRects = function () { var _this = this; var rects = []; this.xDomain.map(function (xVal) { _this.yDomain.map(function (yVal) { rects.push({ x: _this.xScale(xVal), y: _this.yScale(yVal), rx: 3, width: _this.xScale.bandwidth(), height: _this.yScale.bandwidth(), fill: 'rgba(200,200,200,0.03)' }); }); }); return rects; }; HeatMapComponent.prototype.onClick = function (data) { this.select.emit(data); }; HeatMapComponent.prototype.setColors = function () { this.colors = new color_helper_1.ColorHelper(this.scheme, 'linear', this.valueDomain); }; HeatMapComponent.prototype.getLegendOptions = function () { return { scaleType: 'linear', domain: this.valueDomain, colors: this.colors.scale }; }; HeatMapComponent.prototype.updateYAxisWidth = function (_a) { var width = _a.width; this.yAxisWidth = width; this.update(); }; HeatMapComponent.prototype.updateXAxisHeight = function (_a) { var height = _a.height; this.xAxisHeight = height; this.update(); }; HeatMapComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'ngx-charts-heat-map', template: "\n <ngx-charts-chart\n [view]=\"[width, height]\"\n [showLegend]=\"legend\"\n [legendOptions]=\"legendOptions\"\n (legendLabelActivate)=\"onActivate($event)\"\n (legendLabelDeactivate)=\"onDeactivate($event)\"\n (legendLabelClick)=\"onClick($event)\">\n <svg:g [attr.transform]=\"transform\" class=\"heat-map chart\">\n <svg:g ngx-charts-x-axis\n *ngIf=\"xAxis\"\n [xScale]=\"xScale\"\n [dims]=\"dims\"\n [showLabel]=\"showXAxisLabel\"\n [labelText]=\"xAxisLabel\"\n (dimensionsChanged)=\"updateXAxisHeight($event)\">\n </svg:g>\n <svg:g ngx-charts-y-axis\n *ngIf=\"yAxis\"\n [yScale]=\"yScale\"\n [dims]=\"dims\"\n [showLabel]=\"showYAxisLabel\"\n [labelText]=\"yAxisLabel\"\n (dimensionsChanged)=\"updateYAxisWidth($event)\">\n </svg:g>\n <svg:rect *ngFor=\"let rect of rects\"\n [attr.x]=\"rect.x\"\n [attr.y]=\"rect.y\"\n [attr.rx]=\"rect.rx\"\n [attr.width]=\"rect.width\"\n [attr.height]=\"rect.height\"\n [attr.fill]=\"rect.fill\"\n />\n <svg:g ngx-charts-heat-map-cell-series\n [xScale]=\"xScale\"\n [yScale]=\"yScale\"\n [colors]=\"colors\"\n [data]=\"results\"\n [gradient]=\"gradient\"\n (select)=\"onClick($event)\"\n />\n </svg:g>\n </ngx-charts-chart>\n ", changeDetection: core_1.ChangeDetectionStrategy.OnPush, },] }, ]; /** @nocollapse */ HeatMapComponent.ctorParameters = function () { return []; }; HeatMapComponent.propDecorators = { 'legend': [{ type: core_1.Input },], 'xAxis': [{ type: core_1.Input },], 'yAxis': [{ type: core_1.Input },], 'showXAxisLabel': [{ type: core_1.Input },], 'showYAxisLabel': [{ type: core_1.Input },], 'xAxisLabel': [{ type: core_1.Input },], 'yAxisLabel': [{ type: core_1.Input },], 'gradient': [{ type: core_1.Input },], }; return HeatMapComponent; }(base_chart_component_1.BaseChartComponent)); exports.HeatMapComponent = HeatMapComponent; //# sourceMappingURL=heat-map.component.js.map