-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-components): updating echarts ux
- Loading branch information
Showing
8 changed files
with
59 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 28 additions & 26 deletions
54
packages/react-components/src/components/chart/converters/convertOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
import { ChartOptions } from '../types'; | ||
import { EChartsOption } from 'echarts'; | ||
import { DEFAULT_DATA_ZOOM, DEFAULT_TOOL_BOX } from '../eChartsConstants'; | ||
import { DEFAULT_TOOL_BOX } from '../eChartsConstants'; | ||
import { convertGrid } from './convertGrid'; | ||
import { convertTooltip } from './convertTooltip'; | ||
import { useMemo } from 'react'; | ||
import { ChartOptions } from '../types'; | ||
import { EChartsOption, SeriesOption } from 'echarts'; | ||
|
||
type ConvertChartOptions = Pick< | ||
ChartOptions, | ||
'backgroundColor' | 'axis' | 'gestures' | 'legend' | 'significantDigits' | ||
> & { title?: string }; | ||
|
||
/** | ||
* @param options options object to adapt to the echarts | ||
* @returns adapted echarts options | ||
*/ | ||
export const convertOptions = (options: ConvertChartOptions): EChartsOption => { | ||
const { backgroundColor, legend, significantDigits, title } = options; | ||
return { | ||
title: { | ||
text: title, // options.seriesLength === 0 ? 'No data present' : '', | ||
}, | ||
backgroundColor, | ||
grid: convertGrid(legend), | ||
dataZoom: { ...DEFAULT_DATA_ZOOM }, | ||
tooltip: convertTooltip(significantDigits), | ||
toolbox: DEFAULT_TOOL_BOX, | ||
}; | ||
}; | ||
'backgroundColor' | 'axis' | 'gestures' | 'legend' | 'significantDigits' | 'titleText' | 'defaultVisualizationType' | ||
>; | ||
|
||
/** | ||
* Hook that adapts chart options to echarts options. | ||
* | ||
* @param options options object to adapt to the echarts | ||
* @param series options object to adapt to the echarts | ||
* @returns memoized adapted echarts options | ||
*/ | ||
export const useConvertedOptions = (options: ConvertChartOptions) => { | ||
const { backgroundColor, axis, gestures, significantDigits, title } = options; | ||
return useMemo(() => convertOptions(options), [backgroundColor, axis, gestures, significantDigits, title]); | ||
export const useConvertedOptions = ({ | ||
series, | ||
options, | ||
}: { | ||
options: ConvertChartOptions; | ||
series: SeriesOption[]; | ||
}): EChartsOption => { | ||
const { backgroundColor, axis, significantDigits, titleText, defaultVisualizationType } = options; | ||
const text = series.length === 0 ? 'No data present' : titleText ?? defaultVisualizationType ?? ''; | ||
return useMemo( | ||
() => ({ | ||
title: { | ||
text, | ||
top: 10, | ||
}, | ||
backgroundColor, | ||
grid: convertGrid(options.legend), | ||
tooltip: convertTooltip(significantDigits), | ||
toolbox: DEFAULT_TOOL_BOX, | ||
}), | ||
[backgroundColor, axis, significantDigits, text] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters