UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

88 lines 4.92 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("../../utils/common"); var utils_1 = require("../../../../helpers/utils"); var bucketNames_1 = require("../../../../constants/bucketNames"); var commonConfiguration_1 = require("../highcharts/commonConfiguration"); exports.SUPPORTED_MEASURE_BUCKETS = [ bucketNames_1.MEASURES, bucketNames_1.SECONDARY_MEASURES, bucketNames_1.TERTIARY_MEASURES, ]; var PRIMARY_VS_COMPARATIVE_MEASURE_HEIGHT_RATIO = 0.75; var isComparativeMeasurePresent = function (bucketLocalIdentifiers) { return bucketLocalIdentifiers.includes(bucketNames_1.TERTIARY_MEASURES); }; var isTargetMeasurePresent = function (bucketLocalIdentifiers) { return bucketLocalIdentifiers.includes(bucketNames_1.SECONDARY_MEASURES); }; var getValue = function (value, isTarget) { return isTarget ? { target: value === null ? 0 : value, y: 0, } : { y: value, }; }; var getSeriesItemData = function (seriesItem, measureGroup, seriesIndex, measureBucketsLocalIdentifiers) { return seriesItem.map(function (pointValue) { var value = common_1.parseValue(pointValue); var isTarget = exports.isTargetSeries(seriesIndex, measureBucketsLocalIdentifiers); var nullValueProps = isTarget && value === null ? { isNullTarget: true, className: "hidden-empty-series" } : {}; return __assign({}, nullValueProps, getValue(value, isTarget), { format: utils_1.unwrap(measureGroup.items[seriesIndex]).format, marker: { enabled: pointValue !== null, }, name: utils_1.unwrap(measureGroup.items[seriesIndex]).name }); }); }; var getPrimarySeriesMaxPointWidth = function (onlyPrimaryMeasure) { if (!onlyPrimaryMeasure) { return commonConfiguration_1.MAX_POINT_WIDTH * PRIMARY_VS_COMPARATIVE_MEASURE_HEIGHT_RATIO; } return commonConfiguration_1.MAX_POINT_WIDTH; }; var getPrimarySeries = function (seriesItemConfig, onlyPrimaryMeasure) { return (__assign({}, seriesItemConfig, { pointPadding: onlyPrimaryMeasure ? 0.1 : 0.2, maxPointWidth: getPrimarySeriesMaxPointWidth(onlyPrimaryMeasure), zIndex: 1, bulletChartMeasureType: "primary" })); }; var getTargetSeries = function (seriesItemConfig) { return (__assign({}, seriesItemConfig, { type: "bullet", pointPadding: 0, targetOptions: { width: "100%", }, zIndex: 2, bulletChartMeasureType: "target" })); }; var getComparativeSeries = function (seriesItemConfig) { return (__assign({}, seriesItemConfig, { pointPadding: 0, zIndex: 0, bulletChartMeasureType: "comparative" })); }; exports.isPrimarySeries = function (seriesIndex, bucketsLocalIdentifiers) { return seriesIndex === bucketsLocalIdentifiers.indexOf(bucketNames_1.MEASURES); }; exports.isTargetSeries = function (seriesIndex, bucketsLocalIdentifiers) { return seriesIndex === bucketsLocalIdentifiers.indexOf(bucketNames_1.SECONDARY_MEASURES); }; exports.isComparativeSeries = function (seriesIndex, bucketsLocalIdentifiers) { return seriesIndex === bucketsLocalIdentifiers.indexOf(bucketNames_1.TERTIARY_MEASURES); }; var getSeries = function (seriesIndex, seriesItemConfig, measureBucketsLocalIdentifiers) { if (exports.isTargetSeries(seriesIndex, measureBucketsLocalIdentifiers)) { return getTargetSeries(seriesItemConfig); } else if (exports.isComparativeSeries(seriesIndex, measureBucketsLocalIdentifiers)) { return getComparativeSeries(seriesItemConfig); } var onlyPrimaryMeasure = !isComparativeMeasurePresent(measureBucketsLocalIdentifiers) && !isTargetMeasurePresent(measureBucketsLocalIdentifiers); return getPrimarySeries(seriesItemConfig, onlyPrimaryMeasure); }; function getBulletChartSeries(executionResultData, measureGroup, colorStrategy, occupiedMeasureBucketsLocalIdentifiers) { return executionResultData.map(function (seriesItem, seriesIndex) { var seriesItemData = getSeriesItemData(seriesItem, measureGroup, seriesIndex, occupiedMeasureBucketsLocalIdentifiers); var seriesItemConfig = { legendIndex: seriesIndex, data: seriesItemData, name: measureGroup.items[seriesIndex].measureHeaderItem.name, color: colorStrategy.getColorByIndex(seriesIndex), }; return getSeries(seriesIndex, seriesItemConfig, occupiedMeasureBucketsLocalIdentifiers); }); } exports.getBulletChartSeries = getBulletChartSeries; //# sourceMappingURL=bulletChartOptions.js.map