@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular2 and beyond!
147 lines • 6.65 kB
JavaScript
;
var core_1 = require('@angular/core');
var label_helper_1 = require('../common/label.helper');
var SeriesVerticalComponent = (function () {
function SeriesVerticalComponent() {
this.type = 'standard';
this.select = new core_1.EventEmitter();
this.activate = new core_1.EventEmitter();
this.deactivate = new core_1.EventEmitter();
}
SeriesVerticalComponent.prototype.ngOnChanges = function (changes) {
this.update();
};
SeriesVerticalComponent.prototype.update = function () {
var _this = this;
var width;
if (this.series.length) {
width = this.xScale.bandwidth();
}
var d0 = 0;
var total;
if (this.type === 'normalized') {
total = this.series.map(function (d) { return d.value; }).reduce(function (sum, d) { return sum + d; }, 0);
}
this.bars = this.series.map(function (d, index) {
var value = d.value;
var label = d.name;
var formattedLabel = label_helper_1.formatLabel(label);
var roundEdges = _this.type === 'standard';
var bar = {
value: value,
label: label,
roundEdges: roundEdges,
data: d,
width: width,
formattedLabel: formattedLabel,
height: 0,
x: 0,
y: 0
};
if (_this.type === 'standard') {
bar.height = Math.abs(_this.yScale(value) - _this.yScale(0));
bar.x = _this.xScale(label);
if (value < 0) {
bar.y = _this.yScale(0);
}
else {
bar.y = _this.yScale(value);
}
}
else if (_this.type === 'stacked') {
var offset0 = d0;
var offset1 = offset0 + value;
d0 += value;
bar.height = _this.yScale(offset0) - _this.yScale(offset1);
bar.x = 0;
bar.y = _this.yScale(offset1);
bar.offset0 = offset0;
bar.offset1 = offset1;
}
else if (_this.type === 'normalized') {
var offset0 = d0;
var offset1 = offset0 + value;
d0 += value;
if (total > 0) {
offset0 = (offset0 * 100) / total;
offset1 = (offset1 * 100) / total;
}
else {
offset0 = 0;
offset1 = 0;
}
bar.height = _this.yScale(offset0) - _this.yScale(offset1);
bar.x = 0;
bar.y = _this.yScale(offset1);
bar.offset0 = offset0;
bar.offset1 = offset1;
value = (offset1 - offset0).toFixed(2) + '%';
}
if (_this.colors.scaleType === 'ordinal') {
bar.color = _this.colors.getColor(label);
}
else {
if (_this.type === 'standard') {
bar.color = _this.colors.getColor(value);
bar.gradientStops = _this.colors.getLinearGradientStops(value);
}
else {
bar.color = _this.colors.getColor(bar.offset1);
bar.gradientStops = _this.colors.getLinearGradientStops(bar.offset1, bar.offset0);
}
}
bar.tooltipText = "\n <span class=\"tooltip-label\">" + formattedLabel + "</span>\n <span class=\"tooltip-val\">" + value.toLocaleString() + "</span>\n ";
return bar;
});
};
SeriesVerticalComponent.prototype.isActive = function (entry) {
if (!this.activeEntries)
return false;
var item = this.activeEntries.find(function (d) {
return entry.name === d.name && entry.series === d.series;
});
return item !== undefined;
};
SeriesVerticalComponent.prototype.onClick = function (data) {
this.select.emit(data);
};
SeriesVerticalComponent.prototype.trackBy = function (index, bar) {
return bar.label;
};
SeriesVerticalComponent.decorators = [
{ type: core_1.Component, args: [{
selector: 'g[ngx-charts-series-vertical]',
template: "\n <svg:g ngx-charts-bar *ngFor=\"let bar of bars; trackBy: trackBy\"\n [@animationState]=\"'active'\"\n [width]=\"bar.width\"\n [height]=\"bar.height\"\n [x]=\"bar.x\"\n [y]=\"bar.y\"\n [fill]=\"bar.color\"\n [stops]=\"bar.gradientStops\"\n [data]=\"bar.data\"\n [orientation]=\"'vertical'\"\n [roundEdges]=\"bar.roundEdges\"\n [gradient]=\"gradient\"\n [isActive]=\"isActive(bar.data)\"\n (select)=\"onClick($event)\"\n (activate)=\"activate.emit($event)\"\n (deactivate)=\"deactivate.emit($event)\"\n ngx-tooltip\n [tooltipPlacement]=\"'top'\"\n [tooltipType]=\"'tooltip'\"\n [tooltipTitle]=\"bar.tooltipText\">\n </svg:g>\n ",
changeDetection: core_1.ChangeDetectionStrategy.OnPush,
animations: [
core_1.trigger('animationState', [
core_1.transition('* => void', [
core_1.style({
opacity: 1,
transform: '*',
}),
core_1.animate(500, core_1.style({ opacity: 0, transform: 'scale(0)' }))
])
])
]
},] },
];
/** @nocollapse */
SeriesVerticalComponent.ctorParameters = function () { return []; };
SeriesVerticalComponent.propDecorators = {
'dims': [{ type: core_1.Input },],
'type': [{ type: core_1.Input },],
'series': [{ type: core_1.Input },],
'xScale': [{ type: core_1.Input },],
'yScale': [{ type: core_1.Input },],
'colors': [{ type: core_1.Input },],
'gradient': [{ type: core_1.Input },],
'activeEntries': [{ type: core_1.Input },],
'select': [{ type: core_1.Output },],
'activate': [{ type: core_1.Output },],
'deactivate': [{ type: core_1.Output },],
};
return SeriesVerticalComponent;
}());
exports.SeriesVerticalComponent = SeriesVerticalComponent;
//# sourceMappingURL=series-vertical.component.js.map