From 1aa7bbf11710fe4c2059a0cd3ec89e424c461768 Mon Sep 17 00:00:00 2001 From: MiniPear Date: Fri, 15 Sep 2023 12:19:07 +0800 Subject: [PATCH] Change props.spec to props.options (#1) --- README.md | 34 +++++++++---------- src/Chart.tsx | 14 ++++---- test/demos/chart-fetch.tsx | 4 +-- test/demos/chart-loading.tsx | 4 +-- test/demos/chart-options.tsx | 4 +-- test/demos/chart-ref.tsx | 2 +- .../{chart-spec.tsx => chart-renderer.tsx} | 9 +++-- test/demos/chart-style.tsx | 2 +- test/demos/chart-update.tsx | 2 +- test/demos/index.ts | 4 +-- 10 files changed, 39 insertions(+), 40 deletions(-) rename test/demos/{chart-spec.tsx => chart-renderer.tsx} (66%) diff --git a/README.md b/README.md index 9aba816..f8207e0 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ import { Chart } from "@strawberry-vis/g2-rect"; export function Demo() { return ( new Renderer(), []); return ( ({ type: "interval", data, @@ -116,7 +114,7 @@ export function Demo() { }, 1000); }); - return <>{data === null ?

Loading...

: }; + return <>{data === null ?

Loading...

: }; } ``` @@ -181,7 +179,7 @@ register("shape.interval.triangle", (style, context) => { export function Demo() { return ( ; export type ChartProps = { - spec: G2Spec | null; - options?: ChartOptions; + options: G2Spec | null; + renderer?: G2ChartOptions["renderer"]; style?: CSSProperties; onInit?: () => void; }; export const Chart = forwardRef((props, ref) => { - const { spec, style, onInit, options } = props; + const { options, style, onInit, renderer } = props; const containerRef = useRef(null); const chartRef = useRef(); const [init, setInit] = useState(false); @@ -32,8 +32,8 @@ export const Chart = forwardRef((props, ref) => { useEffect(() => { if (containerRef.current) { chartRef.current = new G2Chart({ - ...options, container: containerRef.current, + renderer, }); setInit(true); } @@ -47,11 +47,11 @@ export const Chart = forwardRef((props, ref) => { }, [init]); useEffect(() => { - if (chartRef.current && spec) { - chartRef.current.options(spec); + if (chartRef.current && options) { + chartRef.current.options(options); chartRef.current.render(); } - }, [spec]); + }, [options]); useImperativeHandle(ref, () => chartRef.current, [init]); diff --git a/test/demos/chart-fetch.tsx b/test/demos/chart-fetch.tsx index c219707..67ece2e 100644 --- a/test/demos/chart-fetch.tsx +++ b/test/demos/chart-fetch.tsx @@ -4,7 +4,7 @@ import { render } from "./render"; function Demo() { const [data, setData] = useState[] | null>(null); - const spec = useMemo(() => { + const options = useMemo(() => { if (data === null) return null; return { type: "interval", @@ -26,7 +26,7 @@ function Demo() { }, 1000); }); - return ; + return ; } export const ChartFetch = render(Demo); diff --git a/test/demos/chart-loading.tsx b/test/demos/chart-loading.tsx index a525dc1..57357ad 100644 --- a/test/demos/chart-loading.tsx +++ b/test/demos/chart-loading.tsx @@ -4,7 +4,7 @@ import { render } from "./render"; function Demo() { const [data, setData] = useState[] | null>(null); - const spec = useMemo( + const options = useMemo( () => ({ type: "interval", data, @@ -26,7 +26,7 @@ function Demo() { }, 1000); }); - return <>{data === null ?

loading...

: }; + return <>{data === null ?

loading...

: }; } export const ChartLoading = render(Demo); diff --git a/test/demos/chart-options.tsx b/test/demos/chart-options.tsx index bdfd178..4f0dba0 100644 --- a/test/demos/chart-options.tsx +++ b/test/demos/chart-options.tsx @@ -1,13 +1,11 @@ import React from "react"; -import { Renderer } from "@antv/g-svg"; import { Chart } from "../../src"; import { render } from "./render"; function Demo() { return ( new Renderer(), []); return ( - + ); diff --git a/test/demos/index.ts b/test/demos/index.ts index 0b0d6a5..a57c1d3 100644 --- a/test/demos/index.ts +++ b/test/demos/index.ts @@ -1,7 +1,7 @@ -export { chartSpec } from "./chart-spec"; +export { chartOptions } from "./chart-options"; export { chartUpdate } from "./chart-update"; export { chartStyle } from "./chart-style"; export { chartRef } from "./chart-ref"; -export { chartOptions } from "./chart-options"; +export { chartRenderer } from "./chart-renderer"; export { ChartFetch } from "./chart-fetch"; export { ChartLoading } from "./chart-loading";