SBIN2010 commented on code in PR #43346:
URL: https://github.com/apache/superset/pull/43346#discussion_r3847703945


##########
superset-frontend/plugins/plugin-chart-echarts/src/Butterfly/transformProps.ts:
##########
@@ -0,0 +1,291 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  CurrencyFormatter,
+  ensureIsArray,
+  getColumnLabel,
+  getMetricLabel,
+  getNumberFormatter,
+  NumberFormatter,
+  rgbToHex,
+  tooltipHtml,
+} from '@superset-ui/core';
+import type { ComposeOption } from 'echarts/core';
+import type { BarSeriesOption } from 'echarts/charts';
+import type { CallbackDataParams } from 'echarts/types/src/util/types';
+import { EchartsButterflyChartProps, ButterflyTransformedProps } from 
'./types';
+import { DEFAULT_FORM_DATA } from './constants';
+import { defaultGrid } from '../defaults';
+import { getDefaultTooltip } from '../utils/tooltip';
+import { Refs } from '../types';
+import { NULL_STRING } from '../constants';
+import { getChartPadding, getLegendProps } from '../utils/series';
+import { resolveLegendLayout } from '../utils/legendLayout';
+import { convertInteger } from '../utils/convertInteger';
+
+type EChartsOption = ComposeOption<BarSeriesOption>;
+
+const LABEL_LEFT = { position: 'left' as const };
+const LABEL_RIGHT = { position: 'right' as const };
+
+function formatCategory(value: unknown): string {
+  if (value == null) {
+    return NULL_STRING;
+  }
+  if (typeof value === 'string' || typeof value === 'number') {
+    return String(value);
+  }
+  return String(value);
+}
+
+function formatTooltip(
+  params: CallbackDataParams[],
+  formatter: NumberFormatter | CurrencyFormatter,
+) {
+  const axisParams = params.filter(
+    param => param.seriesName && typeof param.value === 'number',
+  );
+  if (!axisParams.length) {
+    return '';
+  }
+
+  const title = axisParams[0].name;
+  const rows = axisParams.map(param => [
+    param.seriesName!,
+    formatter(Math.abs(param.value as number)),
+  ]);
+
+  return tooltipHtml(rows, title);
+}
+
+export default function transformProps(
+  chartProps: EchartsButterflyChartProps,
+): ButterflyTransformedProps {
+  const {
+    width,
+    height,
+    formData,
+    legendState,
+    queriesData,
+    hooks,
+    theme,
+    inContextMenu,
+  } = chartProps;
+  const refs: Refs = {};
+  const { data = [] } = queriesData[0];
+  const { setDataMask = () => {}, onContextMenu, onLegendStateChanged } = 
hooks;
+
+  const {
+    currencyFormat,
+    groupby,
+    leftMetric,
+    rightMetric,
+    leftColor = { r: 84, g: 112, b: 198, a: 1 },
+    rightColor = { r: 145, g: 204, b: 117, a: 1 },
+    leftLabel,
+    rightLabel,
+    xAxisLabel,
+    yAxisLabel,
+    xAxisFormat,
+    xAxisTitleMargin,
+    yAxisTitleMargin,
+    showLegend,
+    legendMargin,
+    legendOrientation,
+    legendType,
+    legendSort,
+    showValue,
+    xAxisLabelRotation,
+  }: EchartsButterflyChartProps['formData'] = {
+    ...DEFAULT_FORM_DATA,
+    ...formData,
+  };
+
+  const groupbyColumn = ensureIsArray(groupby)[0];
+  const categoryLabel = getColumnLabel(groupbyColumn);
+  const leftMetricLabel = getMetricLabel(leftMetric);
+  const rightMetricLabel = getMetricLabel(rightMetric);
+  const leftSeriesName = leftLabel || leftMetricLabel;
+  const rightSeriesName = rightLabel || rightMetricLabel;

Review Comment:
   fixed in fd74700



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to