Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring use-echarts hook #57

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/echart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ export type EChartProps = UseEChartsOptions &
keyof UseEChartsOptions | EChartsEventProp
>

/**
* EChart component that wraps ECharts functionality in a React component
*
* @example
* ```tsx
* <EChart
* style={{ height: '400px' }}
* xAxis={{ type: 'category', data: ['A', 'B', 'C'] }}
* yAxis={{ type: 'value' }}
* series={[{ type: 'bar', data: [1, 2, 3] }]}
* />
* ```
*/
export const EChart: FC<EChartProps> = ({
// Init
// Initialization options
devicePixelRatio,
height,
locale,
Expand All @@ -25,10 +38,10 @@ export const EChart: FC<EChartProps> = ({
useDirtyRect,
width,

// eChartsInstance
// ECharts instance options
group,

// SetOption
// SetOption options
lazyUpdate,
notMerge,
replaceMerge,
Expand All @@ -39,7 +52,7 @@ export const EChart: FC<EChartProps> = ({
options,
stateAnimation,

// Option
// Chart options
angleAxis,
animation,
animationDelay,
Expand Down Expand Up @@ -82,7 +95,7 @@ export const EChart: FC<EChartProps> = ({
xAxis,
yAxis,

// Events
// Event handlers
onAxisAreaSelected,
onBrush,
onBrushEnd,
Expand Down Expand Up @@ -119,8 +132,9 @@ export const EChart: FC<EChartProps> = ({

...rest
}) => {
// Use ECharts hook
const [ref] = useECharts<HTMLDivElement>({
// Init
// Initialization options
devicePixelRatio,
height,
locale,
Expand All @@ -132,10 +146,10 @@ export const EChart: FC<EChartProps> = ({
useDirtyRect,
width,

// eChartsInstance
// ECharts instance options
group,

// SetOption
// SetOption options
lazyUpdate,
notMerge,
replaceMerge,
Expand All @@ -146,7 +160,7 @@ export const EChart: FC<EChartProps> = ({
options,
stateAnimation,

// Option
// Chart options
angleAxis,
animation,
animationDelay,
Expand Down Expand Up @@ -189,7 +203,7 @@ export const EChart: FC<EChartProps> = ({
xAxis,
yAxis,

// Events
// Event handlers
onAxisAreaSelected,
onBrush,
onBrushEnd,
Expand Down Expand Up @@ -225,5 +239,6 @@ export const EChart: FC<EChartProps> = ({
onTimelinePlayChanged
})

// Render the component
return <div {...rest} ref={ref} />
}
Loading