UNPKG

@swimlane/ngx-charts

Version:

Declarative Charting Framework for Angular2 and beyond!

47 lines 2.35 kB
"use strict"; var core_1 = require('@angular/core'); var platform_browser_1 = require('@angular/platform-browser'); var ScaleLegendComponent = (function () { function ScaleLegendComponent(sanitizer) { this.sanitizer = sanitizer; } ScaleLegendComponent.prototype.ngOnChanges = function (changes) { var gradientValues = this.gradientString(this.colors.range(), this.colors.domain()); this.gradient = this.sanitizer.bypassSecurityTrustStyle("linear-gradient(to bottom, " + gradientValues + ")"); }; /** * Generates the string used in the gradient stylesheet properties * @param {array} colors array of colors * @param {array} splits array of splits on a scale of (0, 1) * @return {string} */ ScaleLegendComponent.prototype.gradientString = function (colors, splits) { // add the 100% splits.push(1); var pairs = []; colors.reverse().forEach(function (c, i) { pairs.push(c + " " + Math.round(splits[i] * 100) + "%"); }); return pairs.join(', '); }; ScaleLegendComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'ngx-charts-scale-legend', template: "\n <div\n class=\"scale-legend\"\n [style.height.px]=\"height\"\n [style.width.px]=\"width\">\n <div class=\"scale-legend-label\">\n <span>{{ valueRange[1].toLocaleString() }}</span>\n </div>\n <div \n class=\"scale-legend-wrap\"\n [style.background]=\"gradient\">\n </div>\n <div class=\"scale-legend-label\">\n <span>{{ valueRange[0].toLocaleString() }}</span>\n </div>\n </div>\n ", changeDetection: core_1.ChangeDetectionStrategy.OnPush },] }, ]; /** @nocollapse */ ScaleLegendComponent.ctorParameters = function () { return [ { type: platform_browser_1.DomSanitizer, }, ]; }; ScaleLegendComponent.propDecorators = { 'valueRange': [{ type: core_1.Input },], 'colors': [{ type: core_1.Input },], 'height': [{ type: core_1.Input },], 'width': [{ type: core_1.Input },], }; return ScaleLegendComponent; }()); exports.ScaleLegendComponent = ScaleLegendComponent; //# sourceMappingURL=scale-legend.component.js.map