@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular
118 lines • 5.78 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Component, Input, Output, EventEmitter, ViewEncapsulation, ChangeDetectionStrategy, ContentChild, TemplateRef } from '@angular/core';
import { treemap, stratify } from 'd3-hierarchy';
import { BaseChartComponent } from '../common/base-chart.component';
import { calculateViewDimensions } from '../common/view-dimensions.helper';
import { ColorHelper } from '../common/color.helper';
var TreeMapComponent = /** @class */ (function (_super) {
__extends(TreeMapComponent, _super);
function TreeMapComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.tooltipDisabled = false;
_this.gradient = false;
_this.select = new EventEmitter();
_this.margin = [10, 10, 10, 10];
return _this;
}
TreeMapComponent.prototype.update = function () {
_super.prototype.update.call(this);
this.dims = calculateViewDimensions({
width: this.width,
height: this.height,
margins: this.margin
});
this.domain = this.getDomain();
this.treemap = treemap().size([this.dims.width, this.dims.height]);
var rootNode = {
name: 'root',
value: 0,
isRoot: true
};
var root = stratify()
.id(function (d) {
var label = d.name;
if (label.constructor.name === 'Date') {
label = label.toLocaleDateString();
}
else {
label = label.toLocaleString();
}
return label;
})
.parentId(function (d) { return (d.isRoot ? null : 'root'); })([rootNode].concat(this.results))
.sum(function (d) { return d.value; });
this.data = this.treemap(root);
this.setColors();
this.transform = "translate(" + this.dims.xOffset + " , " + this.margin[0] + ")";
};
TreeMapComponent.prototype.getDomain = function () {
return this.results.map(function (d) { return d.name; });
};
TreeMapComponent.prototype.onClick = function (data) {
this.select.emit(data);
};
TreeMapComponent.prototype.setColors = function () {
this.colors = new ColorHelper(this.scheme, 'ordinal', this.domain, this.customColors);
};
__decorate([
Input(),
__metadata("design:type", Object)
], TreeMapComponent.prototype, "results", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], TreeMapComponent.prototype, "tooltipDisabled", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], TreeMapComponent.prototype, "valueFormatting", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], TreeMapComponent.prototype, "labelFormatting", void 0);
__decorate([
Input(),
__metadata("design:type", Boolean)
], TreeMapComponent.prototype, "gradient", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], TreeMapComponent.prototype, "select", void 0);
__decorate([
ContentChild('tooltipTemplate', { static: false }),
__metadata("design:type", TemplateRef)
], TreeMapComponent.prototype, "tooltipTemplate", void 0);
TreeMapComponent = __decorate([
Component({
selector: 'ngx-charts-tree-map',
template: "\n <ngx-charts-chart [view]=\"[width, height]\" [showLegend]=\"false\" [animations]=\"animations\">\n <svg:g [attr.transform]=\"transform\" class=\"tree-map chart\">\n <svg:g\n ngx-charts-tree-map-cell-series\n [colors]=\"colors\"\n [data]=\"data\"\n [dims]=\"dims\"\n [tooltipDisabled]=\"tooltipDisabled\"\n [tooltipTemplate]=\"tooltipTemplate\"\n [valueFormatting]=\"valueFormatting\"\n [labelFormatting]=\"labelFormatting\"\n [gradient]=\"gradient\"\n [animations]=\"animations\"\n (select)=\"onClick($event)\"\n />\n </svg:g>\n </ngx-charts-chart>\n ",
styleUrls: ['./tree-map.component.css'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
})
], TreeMapComponent);
return TreeMapComponent;
}(BaseChartComponent));
export { TreeMapComponent };
//# sourceMappingURL=tree-map.component.js.map