"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 }; }