From 6ebe11fe8b2a5455e32e364ef39673a139bd0952 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 8 Jan 2025 13:27:16 +0100 Subject: [PATCH 01/10] fixes for https://github.com/apache/superset/issues/30131 this is to propagate the current locale up to the echarts configuration. --- .../plugin-chart-echarts/src/components/Echart.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 995e3a5351349..1d55afb2dbc04 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -27,6 +27,10 @@ import { Ref, } from 'react'; +import { useSelector } from 'react-redux'; +import { ExplorePageState } from 'src/explore/types'; +import * as echarts from 'echarts/core'; + import { styled } from '@superset-ui/core'; import { use, init, EChartsType } from 'echarts/core'; import { @@ -123,10 +127,14 @@ function Echart( getEchartInstance: () => chartRef.current, })); + const localeObj = useSelector((state: ExplorePageState) => state?.common?.locale); + const lang = require('echarts/lib/i18n/lang' + localeObj.toUpperCase()).default; + echarts.registerLocale(localeObj.toUpperCase(), lang); + useEffect(() => { if (!divRef.current) return; if (!chartRef.current) { - chartRef.current = init(divRef.current); + chartRef.current = init(divRef.current, undefined, { locale: localeObj }); } Object.entries(eventHandlers || {}).forEach(([name, handler]) => { From b8385798e98356dc96d9e24f2d362cd2a0569eb7 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 8 Jan 2025 13:39:39 +0100 Subject: [PATCH 02/10] Update Echart.tsx fixes suggested by bot --- .../plugin-chart-echarts/src/components/Echart.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 1d55afb2dbc04..1f4bc721fabf4 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -127,10 +127,14 @@ function Echart( getEchartInstance: () => chartRef.current, })); - const localeObj = useSelector((state: ExplorePageState) => state?.common?.locale); - const lang = require('echarts/lib/i18n/lang' + localeObj.toUpperCase()).default; - echarts.registerLocale(localeObj.toUpperCase(), lang); - + const localeObj = useSelector((state: ExplorePageState) => state?.common?.locale ?? 'en'); + try { + const lang = require(`echarts/lib/i18n/lang/${localeObj.toUpperCase()}`).default; + echarts.registerLocale(localeObj.toUpperCase(), lang); + } catch (e) { + console.warn(`Locale ${localeObj} not supported in ECharts`); + } + useEffect(() => { if (!divRef.current) return; if (!chartRef.current) { From 39ba031deda4076f8e7e980fde64981ba687231e Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 8 Jan 2025 13:58:34 +0100 Subject: [PATCH 03/10] Update Echart.tsx removing trailing whitespaces --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 1f4bc721fabf4..ae2d22da34111 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -134,7 +134,7 @@ function Echart( } catch (e) { console.warn(`Locale ${localeObj} not supported in ECharts`); } - + useEffect(() => { if (!divRef.current) return; if (!chartRef.current) { From 82d8c7859ad2492bf1f2d0548f0c5828c9aec359 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 8 Jan 2025 14:17:01 +0100 Subject: [PATCH 04/10] Update Echart.tsx prettier changes --- .../plugin-chart-echarts/src/components/Echart.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index ae2d22da34111..7610e5d26d0b5 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -127,9 +127,13 @@ function Echart( getEchartInstance: () => chartRef.current, })); - const localeObj = useSelector((state: ExplorePageState) => state?.common?.locale ?? 'en'); + const localeObj = useSelector( + (state: ExplorePageState) => state?.common?.locale ?? 'en' + ); try { - const lang = require(`echarts/lib/i18n/lang/${localeObj.toUpperCase()}`).default; + const lang = require( + `echarts/lib/i18n/lang/${localeObj.toUpperCase()}` + ).default; echarts.registerLocale(localeObj.toUpperCase(), lang); } catch (e) { console.warn(`Locale ${localeObj} not supported in ECharts`); From 16212db26c4a91388908887df5c3da6fa596e86e Mon Sep 17 00:00:00 2001 From: CAPELLI Giampaolo Date: Wed, 8 Jan 2025 14:50:10 +0100 Subject: [PATCH 05/10] prettier --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 7610e5d26d0b5..d4b2d709b8ea9 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -128,11 +128,11 @@ function Echart( })); const localeObj = useSelector( - (state: ExplorePageState) => state?.common?.locale ?? 'en' + (state: ExplorePageState) => state?.common?.locale ?? 'en', ); try { const lang = require( - `echarts/lib/i18n/lang/${localeObj.toUpperCase()}` + `echarts/lib/i18n/lang/${localeObj.toUpperCase()}`, ).default; echarts.registerLocale(localeObj.toUpperCase(), lang); } catch (e) { From c54ba26297b91dfaf228964afd76ecb8047b9101 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Wed, 8 Jan 2025 21:03:05 +0100 Subject: [PATCH 06/10] Apply suggestions from code review Co-authored-by: JUST.in DO IT --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index d4b2d709b8ea9..21f55ab94560b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -29,7 +29,7 @@ import { import { useSelector } from 'react-redux'; import { ExplorePageState } from 'src/explore/types'; -import * as echarts from 'echarts/core'; +import { registerLocale } from 'echarts/core'; import { styled } from '@superset-ui/core'; import { use, init, EChartsType } from 'echarts/core'; From c4b081c6c1bcd2caf30e4c060aaefe55adb5024a Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 16 Jan 2025 10:26:38 +0100 Subject: [PATCH 07/10] Update superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx Co-authored-by: Jillian --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 21f55ab94560b..4849ac3a24da3 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -132,7 +132,7 @@ function Echart( ); try { const lang = require( - `echarts/lib/i18n/lang/${localeObj.toUpperCase()}`, + `echarts/lib/i18n/lang${localeObj.toUpperCase()}`, ).default; echarts.registerLocale(localeObj.toUpperCase(), lang); } catch (e) { From ac15e38230968b620c9d5931126c44ed7a8b0189 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 16 Jan 2025 10:27:00 +0100 Subject: [PATCH 08/10] Update superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx Co-authored-by: Jillian --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 4849ac3a24da3..10c5daf9151ab 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -134,7 +134,7 @@ function Echart( const lang = require( `echarts/lib/i18n/lang${localeObj.toUpperCase()}`, ).default; - echarts.registerLocale(localeObj.toUpperCase(), lang); + registerLocale(localeObj.toUpperCase(), lang); } catch (e) { console.warn(`Locale ${localeObj} not supported in ECharts`); } From 9e13ea294a4555a7afbd30cce00960ac53a21825 Mon Sep 17 00:00:00 2001 From: Giampaolo Capelli Date: Thu, 16 Jan 2025 10:32:30 +0100 Subject: [PATCH 09/10] Update Echart.tsx --- .../plugin-chart-echarts/src/components/Echart.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index 10c5daf9151ab..cb4321e47800b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -127,22 +127,22 @@ function Echart( getEchartInstance: () => chartRef.current, })); - const localeObj = useSelector( + const locale = useSelector( (state: ExplorePageState) => state?.common?.locale ?? 'en', - ); + ).toUpperCase(); try { const lang = require( - `echarts/lib/i18n/lang${localeObj.toUpperCase()}`, + `echarts/lib/i18n/lang${locale}`, ).default; - registerLocale(localeObj.toUpperCase(), lang); + registerLocale(locale, lang); } catch (e) { - console.warn(`Locale ${localeObj} not supported in ECharts`); + console.warn(`Locale ${locale} not supported in ECharts`); } useEffect(() => { if (!divRef.current) return; if (!chartRef.current) { - chartRef.current = init(divRef.current, undefined, { locale: localeObj }); + chartRef.current = init(divRef.current, null, { locale }); } Object.entries(eventHandlers || {}).forEach(([name, handler]) => { @@ -156,7 +156,7 @@ function Echart( }); chartRef.current.setOption(echartOptions, true); - }, [echartOptions, eventHandlers, zrEventHandlers]); + }, [echartOptions, eventHandlers, zrEventHandlers, locale]); // highlighting useEffect(() => { From 90506f28141d98ddf980119ab80694a6ff3092f1 Mon Sep 17 00:00:00 2001 From: CAPELLI Giampaolo Date: Fri, 17 Jan 2025 09:53:54 +0100 Subject: [PATCH 10/10] prettier --- .../plugins/plugin-chart-echarts/src/components/Echart.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx index cb4321e47800b..feab6a3454601 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx @@ -131,9 +131,7 @@ function Echart( (state: ExplorePageState) => state?.common?.locale ?? 'en', ).toUpperCase(); try { - const lang = require( - `echarts/lib/i18n/lang${locale}`, - ).default; + const lang = require(`echarts/lib/i18n/lang${locale}`).default; registerLocale(locale, lang); } catch (e) { console.warn(`Locale ${locale} not supported in ECharts`);