123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- "use strict";
- exports.__esModule = true;
- exports.default = transformProps;
- var _isTruthy = _interopRequireDefault(require("./utils/isTruthy"));
- var _utils = require("./utils");
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
- const NOOP = () => {};
- const grabD3Format = (chartProps, targetMetric) => {
- let foundFormatter;
- chartProps.datasource.metrics.forEach(metric => {
- if (metric.d3format && metric.metric_name === targetMetric) {
- foundFormatter = metric.d3format;
- }
- });
- return foundFormatter;
- };
- function transformProps(chartProps) {
- const {
- width,
- height,
- annotationData,
- datasource,
- formData,
- hooks,
- queryData
- } = chartProps;
- const {
- onAddFilter = NOOP,
- onError = NOOP
- } = hooks;
- const {
- annotationLayers,
- barStacked,
- bottomMargin,
- colorPicker,
- colorScheme,
- comparisonType,
- contribution,
- donut,
- entity,
- labelsOutside,
- leftMargin,
- lineInterpolation,
- maxBubbleSize,
- orderBars,
- pieLabelType,
- reduceXTicks,
- richTooltip,
- sendTimeRange,
- showBarValue,
- showBrush,
- showControls,
- showLabels,
- showLegend,
- showMarkers,
- size,
- stackedStyle,
- vizType,
- x,
- xAxisFormat,
- xAxisLabel,
- xAxisShowminmax,
- xLogScale,
- xTicksLayout,
- y,
- yAxisBounds,
- yAxisLabel,
- yAxisShowminmax,
- yLogScale
- } = formData;
- let {
- numberFormat,
- yAxisFormat,
- yAxis2Format
- } = formData;
- const rawData = queryData.data || [];
- const data = Array.isArray(rawData) ? rawData.map(row => _extends({}, row, {
- key: (0, _utils.formatLabel)(row.key, datasource.verboseMap)
- })) : rawData;
- if (chartProps.formData.vizType === 'pie') {
- numberFormat = numberFormat || grabD3Format(chartProps, chartProps.formData.metric);
- } else if (chartProps.formData.vizType === 'dual_line') {
- yAxisFormat = yAxisFormat || grabD3Format(chartProps, chartProps.formData.metric);
- yAxis2Format = yAxis2Format || grabD3Format(chartProps, chartProps.formData.metric2);
- } else if (['line', 'dist_bar', 'bar', 'area'].includes(chartProps.formData.vizType)) {
- yAxisFormat = yAxisFormat || grabD3Format(chartProps, chartProps.formData.metrics[0]);
- }
- return {
- width,
- height,
- data,
- annotationData,
- annotationLayers,
- areaStackedStyle: stackedStyle,
- baseColor: colorPicker,
- bottomMargin,
- colorScheme,
- comparisonType,
- contribution,
- entity,
- isBarStacked: barStacked,
- isDonut: donut,
- isPieLabelOutside: labelsOutside,
- leftMargin,
- lineInterpolation,
- maxBubbleSize: parseInt(maxBubbleSize, 10),
- numberFormat,
- onBrushEnd: (0, _isTruthy.default)(sendTimeRange) ? timeRange => {
- onAddFilter('__time_range', timeRange, false, true);
- } : undefined,
- onError,
- orderBars,
- pieLabelType,
- reduceXTicks,
- showBarValue,
- showBrush,
- showControls,
- showLabels,
- showLegend,
- showMarkers,
- sizeField: size,
- useRichTooltip: richTooltip,
- vizType,
- xAxisFormat,
- xAxisLabel,
- xAxisShowMinMax: xAxisShowminmax,
- xField: x,
- xIsLogScale: xLogScale,
- xTicksLayout,
- yAxisFormat,
- yAxis2Format,
- yAxisBounds,
- yAxisLabel,
- yAxisShowMinMax: yAxisShowminmax,
- yField: y,
- yIsLogScale: yLogScale
- };
- }
|