rusackas commented on code in PR #37965: URL: https://github.com/apache/superset/pull/37965#discussion_r2854413644
########## superset-frontend/plugins/plugin-chart-echarts/src/utils/themeOverrides.ts: ########## @@ -0,0 +1,89 @@ +/** + * 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 { mergeWith, isPlainObject } from 'lodash'; + +/** + * Custom merge function for ECharts theme overrides. + * + * This function extends lodash's mergeWith with special handling: + * 1. Arrays in source values replace destination arrays entirely (backward compatibility) + * 2. When source is a plain object and destination is an array, the object is merged + * into each array item (allowing default styles to be applied to all items) + * + * This enables theme authors to write intuitive overrides like: + * ```js + * echartsOptionsOverridesByChartType: { + * echarts_bar: { + * series: { itemStyle: { borderRadius: 4 } }, // Applied to ALL series + * yAxis: { axisLabel: { rotate: 45 } } // Applied to ALL y-axes + * } + * } + * ``` + * + * Without this special handling, specifying `series` or `yAxis` as objects would + * fail because the chart's actual values are arrays, and standard object merging + * doesn't make sense for array-to-object merges. + * + * @param sources - Objects to merge (rightmost wins, with special array handling) + * @returns Merged object with the custom array-object merge behavior + * + * @example + * // Chart has multiple series: + * const chartOptions = { + * series: [ + * { type: 'bar', name: 'Revenue', data: [1, 2, 3] }, + * { type: 'bar', name: 'Profit', data: [4, 5, 6] } + * ] + * }; + * + * // Theme override with object (not array): + * const override = { + * series: { itemStyle: { borderRadius: 4 } } + * }; + * + * // Result: borderRadius applied to EACH series + * mergeEchartsThemeOverrides(chartOptions, override); + * // { + * // series: [ + * // { type: 'bar', name: 'Revenue', data: [1, 2, 3], itemStyle: { borderRadius: 4 } }, + * // { type: 'bar', name: 'Profit', data: [4, 5, 6], itemStyle: { borderRadius: 4 } } + * // ] + * // } + */ +export function mergeEchartsThemeOverrides<T = any>(...sources: any[]): T { + const customizer = (objValue: any, srcValue: any): any => { Review Comment: I'll look into this as soon as I can, but might try to squeeze this into 6.1 as-is if I can't get to it. -- 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]
