Skip to content

Commit

Permalink
feat(platform): chart support locale
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Jul 7, 2023
1 parent 3d3fa93 commit ff75a14
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/platform/src/app/components/chart/Chart.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { AppTheme } from '../../utils/types';
import type { DLang } from '@react-devui/ui/utils/types';

import * as echarts from 'echarts';
import { cloneDeep, merge } from 'lodash';
import { useEffect, useRef, useState } from 'react';

import { useAsync, useResize } from '@react-devui/hooks';
import { useAsync, useResize, useStorage } from '@react-devui/hooks';
import { getClassName } from '@react-devui/utils';

import { STORAGE_KEY } from '../../config/storage';
import chartTheme from './theme.json';

export interface AppChartProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
Expand Down Expand Up @@ -34,6 +36,7 @@ export function AppChart(props: AppChartProps): JSX.Element | null {
const async = useAsync();

const [theme, setTheme] = useState<AppTheme | null>(null);
const languageStorage = useStorage<DLang>(...STORAGE_KEY.language);

useEffect(() => {
for (const theme of ['light', 'dark'] as const) {
Expand Down Expand Up @@ -65,15 +68,15 @@ export function AppChart(props: AppChartProps): JSX.Element | null {
}
)
),
{ renderer: aRenderer }
{ renderer: aRenderer, locale: languageStorage.value === 'zh-CN' ? 'ZH' : 'EN' }
);
onInit(instance);
return () => {
instance.dispose();
};
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [aRenderer, theme]);
}, [aRenderer, theme, languageStorage.value]);

useResize(elRef, () => {
dataRef.current.clearTid?.();
Expand Down

0 comments on commit ff75a14

Please sign in to comment.