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


##########
superset-frontend/plugins/plugin-chart-echarts/test/Butterfly/controlPanel.test.ts:
##########
@@ -0,0 +1,83 @@
+/**
+ * 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 { SqlaFormData } from "@superset-ui/core";
+
+const mockShiftMetric = jest
+  .fn()
+  .mockReturnValueOnce("left_sum")
+  .mockReturnValueOnce("right_sum");
+const mockShiftColumn = jest.fn(() => "category");
+
+jest.mock("@superset-ui/chart-controls", () => {
+  const actual = jest.requireActual("@superset-ui/chart-controls");
+  return {
+    ...actual,
+    getStandardizedControls: jest.fn(() => ({
+      shiftMetric: mockShiftMetric,
+      shiftColumn: mockShiftColumn,
+    })),
+  };
+});

Review Comment:
   This test file uses double quotes throughout, while the surrounding 
plugin-chart-echarts tests use single quotes (and the repo ESLint/Prettier 
config typically enforces single quotes). Please reformat to match the project 
style to avoid lint failures in CI.



##########
superset-frontend/plugins/plugin-chart-echarts/src/Butterfly/index.ts:
##########
@@ -0,0 +1,54 @@
+/**
+ * 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 { t } from '@apache-superset/core/translation';
+import { ChartMetadata, ChartPlugin } from '@superset-ui/core';
+import buildQuery from './buildQuery';
+import controlPanel from './controlPanel';
+import transformProps from './transformProps';
+import { EchartsButterflyChartProps, EchartsButterflyFormData } from './types';
+
+export default class EchartsButterflyChartPlugin extends ChartPlugin<
+  EchartsButterflyFormData,
+  EchartsButterflyChartProps
+> {
+  constructor() {
+    super({
+      buildQuery,
+      controlPanel,
+      loadChart: () => import('./Butterfly'),
+      metadata: new ChartMetadata({
+        credits: ['https://echarts.apache.org'],
+        category: t('Comparison'),
+        description: t(
+          'A butterfly chart compares two metrics across categories using 
horizontal bars ' +
+            'that extend left and right from a central axis.',
+        ),
+        name: t('Butterfly Chart'),
+        tags: [
+          t('Categorical'),
+          t('Comparison'),
+          t('ECharts'),
+          t('Multi-Variables'),
+        ],
+        thumbnail: '',
+      }),

Review Comment:
   `ChartMetadata` requires a `thumbnail` string; setting it to an empty string 
is likely to render a blank/broken thumbnail in the viz picker. Please add a 
real thumbnail asset under `src/Butterfly/images/` (and optionally 
`thumbnail-dark.png`/example gallery) and import it here, matching the pattern 
used by other ECharts plugins (e.g. `Waterfall/index.ts`).



##########
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:
   `getMetricLabel(leftMetric/rightMetric)` will throw if either metric is 
unset (it dereferences `metric.label` without optional chaining). This can 
happen when switching viz types or while the form is incomplete; `buildQuery` 
already tolerates missing `left_metric/right_metric`, so `transformProps` 
should defensively handle undefined metrics (e.g., default to '' and/or return 
empty series) to avoid a runtime crash.



-- 
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