UNPKG

@nova-ui/dashboards

Version:

Nova Dashboards is a framework designed to provide feature developers with a common solution for presenting data coming from various sources within a single view, as well as a set of predefined widget visualizations that are 100% configuration-driven and

129 lines 5.93 kB
"use strict"; // © 2022 SolarWinds Worldwide, LLC. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var CategoryChartUtilService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.CategoryChartUtilService = void 0; const tslib_1 = require("tslib"); const core_1 = require("@angular/core"); const charts_1 = require("@nova-ui/charts"); const types_1 = require("../components/proportional-widget/types"); let CategoryChartUtilService = CategoryChartUtilService_1 = class CategoryChartUtilService { /** * Combines each of IDataSeries with accessors, renderer and scales provided * * @param data * @param accessors * @param renderer * @param scales * * @returns resulting set of IChartAssistSeries */ static buildChartSeries(data, accessors, renderer, scales) { const result = (data || []).map((s) => ({ ...s, accessors, renderer, scales, })); return result; } static getChartAttributes(chartType, colors, markers) { const t = CategoryChartUtilService_1.getChartTools(chartType); const result = { grid: t.gridFunction(), accessors: t.accessorFunction(colors, markers), renderer: t.rendererFunction(), scales: t.scaleFunction(), }; if (t.preprocessor) { result.preprocessor = t.preprocessor; } return result; } static getChartTools(chartType) { const radialChartAccessors = (colors) => { const accessors = new charts_1.RadialAccessors(colors); accessors.series.color = (seriesId, series) => series.color ?? colors.get(seriesId); return accessors; }; function barChartAccessors(colors, markers) { // TODO: Refactor to accept config reference from arguments not from outer context // @ts-ignore: TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.; // An outer value of 'this' is shadowed by this container. const accessors = (0, charts_1.barAccessors)(this.config, colors, markers); accessors.series.color = (seriesId, series) => series.color ?? colors?.get(seriesId); // TODO: Remove custom accessor after fixing NUI-3688 in charts accessors.data.value = (d) => Number.isFinite(d) ? d : d.value; return accessors; } const chartTools = { [types_1.ProportionalWidgetChartTypes.DonutChart]: { preprocessor: charts_1.radial, gridFunction: charts_1.radialGrid, rendererFunction: () => new charts_1.RadialRenderer(), // TODO: replace with correct type accessorFunction: radialChartAccessors, scaleFunction: charts_1.radialScales, }, [types_1.ProportionalWidgetChartTypes.PieChart]: { preprocessor: charts_1.radial, gridFunction: charts_1.radialGrid, rendererFunction: () => new charts_1.PieRenderer(), // TODO: replace with correct type accessorFunction: radialChartAccessors, scaleFunction: charts_1.radialScales, }, [types_1.ProportionalWidgetChartTypes.HorizontalBarChart]: { config: { horizontal: true }, gridFunction() { return (0, charts_1.barGrid)(this.config); }, rendererFunction: () => new charts_1.BarRenderer({ highlightStrategy: new charts_1.BarSeriesHighlightStrategy("y"), }), accessorFunction: barChartAccessors, scaleFunction() { return (0, charts_1.barScales)(this.config); }, }, [types_1.ProportionalWidgetChartTypes.VerticalBarChart]: { config: { horizontal: false }, gridFunction() { return (0, charts_1.barGrid)(this.config); }, rendererFunction: () => new charts_1.BarRenderer({ highlightStrategy: new charts_1.BarSeriesHighlightStrategy("x"), }), accessorFunction: barChartAccessors, scaleFunction() { return (0, charts_1.barScales)(this.config); }, }, }; return chartTools[chartType]; } }; exports.CategoryChartUtilService = CategoryChartUtilService; exports.CategoryChartUtilService = CategoryChartUtilService = CategoryChartUtilService_1 = tslib_1.__decorate([ (0, core_1.Injectable)() ], CategoryChartUtilService); //# sourceMappingURL=category-chart-util.service.js.map