transformProps.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = transformProps;
  4. var _isTruthy = _interopRequireDefault(require("./utils/isTruthy"));
  5. var _utils = require("./utils");
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. 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); }
  8. const NOOP = () => {};
  9. const grabD3Format = (chartProps, targetMetric) => {
  10. let foundFormatter;
  11. chartProps.datasource.metrics.forEach(metric => {
  12. if (metric.d3format && metric.metric_name === targetMetric) {
  13. foundFormatter = metric.d3format;
  14. }
  15. });
  16. return foundFormatter;
  17. };
  18. function transformProps(chartProps) {
  19. const {
  20. width,
  21. height,
  22. annotationData,
  23. datasource,
  24. formData,
  25. hooks,
  26. queryData
  27. } = chartProps;
  28. const {
  29. onAddFilter = NOOP,
  30. onError = NOOP
  31. } = hooks;
  32. const {
  33. annotationLayers,
  34. barStacked,
  35. bottomMargin,
  36. colorPicker,
  37. colorScheme,
  38. comparisonType,
  39. contribution,
  40. donut,
  41. entity,
  42. labelsOutside,
  43. leftMargin,
  44. lineInterpolation,
  45. maxBubbleSize,
  46. orderBars,
  47. pieLabelType,
  48. reduceXTicks,
  49. richTooltip,
  50. sendTimeRange,
  51. showBarValue,
  52. showBrush,
  53. showControls,
  54. showLabels,
  55. showLegend,
  56. showMarkers,
  57. size,
  58. stackedStyle,
  59. vizType,
  60. x,
  61. xAxisFormat,
  62. xAxisLabel,
  63. xAxisShowminmax,
  64. xLogScale,
  65. xTicksLayout,
  66. y,
  67. yAxisBounds,
  68. yAxisLabel,
  69. yAxisShowminmax,
  70. yLogScale
  71. } = formData;
  72. let {
  73. numberFormat,
  74. yAxisFormat,
  75. yAxis2Format
  76. } = formData;
  77. const rawData = queryData.data || [];
  78. const data = Array.isArray(rawData) ? rawData.map(row => _extends({}, row, {
  79. key: (0, _utils.formatLabel)(row.key, datasource.verboseMap)
  80. })) : rawData;
  81. if (chartProps.formData.vizType === 'pie') {
  82. numberFormat = numberFormat || grabD3Format(chartProps, chartProps.formData.metric);
  83. } else if (chartProps.formData.vizType === 'dual_line') {
  84. yAxisFormat = yAxisFormat || grabD3Format(chartProps, chartProps.formData.metric);
  85. yAxis2Format = yAxis2Format || grabD3Format(chartProps, chartProps.formData.metric2);
  86. } else if (['line', 'dist_bar', 'bar', 'area'].includes(chartProps.formData.vizType)) {
  87. yAxisFormat = yAxisFormat || grabD3Format(chartProps, chartProps.formData.metrics[0]);
  88. }
  89. return {
  90. width,
  91. height,
  92. data,
  93. annotationData,
  94. annotationLayers,
  95. areaStackedStyle: stackedStyle,
  96. baseColor: colorPicker,
  97. bottomMargin,
  98. colorScheme,
  99. comparisonType,
  100. contribution,
  101. entity,
  102. isBarStacked: barStacked,
  103. isDonut: donut,
  104. isPieLabelOutside: labelsOutside,
  105. leftMargin,
  106. lineInterpolation,
  107. maxBubbleSize: parseInt(maxBubbleSize, 10),
  108. numberFormat,
  109. onBrushEnd: (0, _isTruthy.default)(sendTimeRange) ? timeRange => {
  110. onAddFilter('__time_range', timeRange, false, true);
  111. } : undefined,
  112. onError,
  113. orderBars,
  114. pieLabelType,
  115. reduceXTicks,
  116. showBarValue,
  117. showBrush,
  118. showControls,
  119. showLabels,
  120. showLegend,
  121. showMarkers,
  122. sizeField: size,
  123. useRichTooltip: richTooltip,
  124. vizType,
  125. xAxisFormat,
  126. xAxisLabel,
  127. xAxisShowMinMax: xAxisShowminmax,
  128. xField: x,
  129. xIsLogScale: xLogScale,
  130. xTicksLayout,
  131. yAxisFormat,
  132. yAxis2Format,
  133. yAxisBounds,
  134. yAxisLabel,
  135. yAxisShowMinMax: yAxisShowminmax,
  136. yField: y,
  137. yIsLogScale: yLogScale
  138. };
  139. }