Skip to content

Commit ffb8d9f

Browse files
committed
docs(appkit-ui): document echarts registration contract for custom options
- Document on the `options` prop that only the built-in feature set is registered; extra ECharts features (dataZoom, toolbox, markLine, ...) must be registered by the consumer via `use` from "echarts/core", which requires resolving the same echarts module instance/version. - Note in the registration block that tooltip-driven axisPointer ships with TooltipComponent, and that `use()` must stay co-located with BaseChart because package.json#sideEffects declares JS modules pure. - Fix the type-only import comment: the ECharts type is used for the stored instance ref. - Add tests: custom `options` with a registered component logs no registration errors; empty data renders the "No data" fallback. Co-authored-by: Isaac Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
1 parent 5153db6 commit ffb8d9f

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎packages/appkit-ui/src/react/charts/__tests__/base.test.tsx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,31 @@ describe("BaseChart ECharts registration", () => {
205205
);
206206
expect(registrationErrors).toEqual([]);
207207
});
208+
209+
test("renders custom `options` using a registered component without registration errors", async () => {
210+
const { container } = render(
211+
<BaseChart
212+
data={cartesianData}
213+
chartType="line"
214+
xKey="month"
215+
yKey="revenue"
216+
options={{ title: { subtext: "custom" } }}
217+
/>,
218+
);
219+
220+
await waitFor(() =>
221+
expect(container.querySelector("canvas")).not.toBeNull(),
222+
);
223+
expect(registrationErrors).toEqual([]);
224+
});
225+
226+
test("renders the no-data fallback for empty data without mounting ECharts", () => {
227+
const { container, getByText } = render(
228+
<BaseChart data={[]} chartType="line" />,
229+
);
230+
231+
expect(getByText("No data")).toBeTruthy();
232+
expect(container.querySelector("canvas")).toBeNull();
233+
expect(registrationErrors).toEqual([]);
234+
});
208235
});

‎packages/appkit-ui/src/react/charts/base.tsx‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Type-only import: erased at compile time, does not pull the full echarts
2-
// bundle in. echarts-for-react's API is typed against this `ECharts` class.
2+
// bundle in. The `ECharts` type is used for the stored ECharts instance ref.
33
import type { ECharts } from "echarts";
44
import {
55
BarChart,
@@ -50,6 +50,14 @@ import type {
5050
// toolbox, markLine), register it here. Consumers passing custom `options`
5151
// that need extra features can register them in their own app via
5252
// `import { use } from "echarts/core"`.
53+
//
54+
// Note: tooltip-driven axisPointer is bundled with `TooltipComponent`, so no
55+
// explicit AxisPointerComponent registration is needed.
56+
//
57+
// This `use()` call must stay co-located in the same module as `BaseChart`:
58+
// `package.json#sideEffects` declares JS modules side-effect free, so moving
59+
// registration to a separate import-for-side-effect module would let bundlers
60+
// drop it during tree-shaking.
5361
echarts.use([
5462
// Series types used by the option builders
5563
LineChart, // line + area charts (area = line with areaStyle)
@@ -140,7 +148,17 @@ export interface BaseChartProps {
140148
min?: number;
141149
/** Max value for heatmap color scale */
142150
max?: number;
143-
/** Additional ECharts options to merge */
151+
/**
152+
* Additional ECharts options to merge.
153+
*
154+
* Only the built-in feature set is registered by this package, so options
155+
* referencing extra ECharts features (`dataZoom`, `toolbox`, `markLine`,
156+
* `markArea`, `graphic`, `dataset`, top-level `axisPointer`, ...) require
157+
* registering them in your app via `import { use } from "echarts/core"`.
158+
* This only works when your `echarts` resolves to the same module
159+
* instance/version as this package's (the registry is a singleton;
160+
* duplicate echarts copies won't share registrations).
161+
*/
144162
options?: Record<string, unknown>;
145163
/** Additional CSS classes */
146164
className?: string;

0 commit comments

Comments
 (0)