villebro commented on code in PR #22107: URL: https://github.com/apache/superset/pull/22107#discussion_r1034396696
########## superset-frontend/plugins/plugin-chart-echarts/src/Bubble/transformProps.ts: ########## @@ -0,0 +1,188 @@ +/** + * 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 { EChartsCoreOption, ScatterSeriesOption } from 'echarts'; +import { extent } from 'd3-array'; +import { + CategoricalColorNamespace, + getNumberFormatter, + AxisType, +} from '@superset-ui/core'; +import { EchartsBubbleChartProps, EchartsBubbleFormData } from './types'; +import { DEFAULT_FORM_DATA, MINIMUM_BUBBLE_SIZE } from './constants'; +import { defaultGrid, defaultTooltip } from '../defaults'; +import { getLegendProps } from '../utils/series'; +import { LegendOrientation, LegendType } from '../types'; +import { parseYAxisBound } from '../utils/controls'; + +function normalizeSymbolSize( + nodes: ScatterSeriesOption[], + maxBubbleValue: number, +) { + const [bubbleMinValue, bubbleMaxValue] = extent(nodes, x => x.data![0][2]); + const nodeSpread = bubbleMaxValue - bubbleMinValue; + nodes.forEach(node => { + // eslint-disable-next-line no-param-reassign + node.symbolSize = + (((node.data![0][2] - bubbleMinValue) / nodeSpread) * + (maxBubbleValue * 2) || 0) + MINIMUM_BUBBLE_SIZE; + }); +} + +export function formatBubbleLabel( + params: any, + xAxisLabel: string, + yAxisLabel: string, + sizeLabel: string, +) { + const title = params.data[4] + ? `${params.data[3]} <sub>(${params.data[4]})</sub>` + : params.data[3]; + + return `<p>${title}</p> + ${xAxisLabel}: ${params.data[0]} <br/> + ${yAxisLabel}: ${params.data[1]} <br/> + ${sizeLabel}: ${params.data[2]}`; Review Comment: Looking at the example chart in the World Bank Dashboard, the size is in billions, while t x-axis and y-axis are essentially percentages: <img width="765" alt="image" src="https://user-images.githubusercontent.com/33317356/204468139-f738e78a-c550-4129-9efb-6c4b9b0210cb.png"> I think x and y axes will usually be in the same scale, but since we already have separate formatters for them and no separate tooltip formatter, I would maybe just propose adding a size formatter, and then using the same formatters in the tooltip for now (later on if people really want to use separate formatters on the tooltip we can add that, but let's not go for 6 formatters quite yet 😬). -- 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]
