Skip to content

Commit 64c5341

Browse files
committed
we now have plugins, however, we still have one large JS chunk
1 parent c2fa73f commit 64c5341

File tree

20 files changed

+120
-61
lines changed

20 files changed

+120
-61
lines changed

chartlets.js/CHANGES.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@
88
- `chartlets-demo` Chartlets demo which uses the above
99
- Allow for different component implementation bases, therefore
1010
make corresponding dependencies optional and dynamically check at runtime
11-
whether they are available. We may also think of going further by
12-
using dedicated implementation packages:
13-
- `chartlets.py.vega` Defines the `VegaChart` component
14-
- `chartlets.js.mui` Registers MUI impls. of the standard components
15-
- `chartlets.js.vega` Registers Vega React impl. of the `VegaChart` component
11+
whether they are available.
1612

1713
## Version 0.0.30 (in development)
1814

19-
* Allow for different chart providers:
20-
- Renamed `Plot` into `VegaChart`.
21-
- `VegaChart` is defined only if `vega-altair` is installed.
22-
23-
* The `Plot` component now respects a `theme` property. If not given,
24-
it will respect the current MUI theme mode `"dark"`.
15+
* Chartlets now allows for different component providers.
16+
Therefore, Vega-based `Plot` and MUI components have been made optional.
17+
To activate, use the new `plugins: Plugin[]` option of `FrameworkOptions`.
18+
```TypeScript
19+
import { initializeContributions } from "chartlets";
20+
import mui from "chartlets/plugins/mui";
21+
import vega from "chartlets/plugins/vega";
22+
23+
initializeContributions({ plugins: [mui, vega], ... })
24+
```
25+
In addition:
26+
- Renamed `Plot` into `VegaChart` and moved to `src/plugins/vega`.
27+
- Moved other MUI components into `src/plugins/mui`.
28+
29+
* The new `VegaChart` component respects a `theme` property. If not given,
30+
it will respect the current theme mode `"dark"` otherwise fallback to the
31+
Vega default theme.
2532

2633
## Version 0.0.29 (from 2024/11/26)
2734

chartlets.js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chartlets.js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"@fontsource/roboto": "^5.1.0",
5151
"@mui/material": "^6.1.5",
5252
"microdiff": "^1.4.0",
53-
"react": "^18.3.1",
54-
"react-dom": "^18.3.1",
53+
"react": ">=18",
54+
"react-dom": ">=18",
5555
"react-vega": "^7.6.0",
5656
"zustand": "^5.0.0"
5757
},

chartlets.js/src/demo/App.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@ import { CssBaseline, ThemeProvider, createTheme } from "@mui/material";
22
import Typography from "@mui/material/Typography";
33

44
import { initializeContributions } from "@/lib";
5+
import mui from "@/lib/plugins/mui";
6+
import vega from "@/lib/plugins/vega";
7+
8+
import { type AppState, appStore } from "@/demo/store";
59
import ExtensionsInfo from "./components/ExtensionInfo";
6-
import ControlBar from "@/demo/components/ControlBar";
10+
import ControlBar from "./components/ControlBar";
711
import PanelsControl from "./components/PanelsControl";
812
import PanelsRow from "./components/PanelsRow";
9-
import { appStore } from "@/demo/store";
10-
import { getValue, setValue } from "@/lib/utils/objPath";
1113

1214
initializeContributions({
15+
plugins: [mui, vega],
1316
hostStore: {
1417
// Let Chartlets listen to changes in application state.
1518
subscribe: (listener: () => void) => appStore.subscribe(listener),
1619
// Compute a property value and return it. We simply use getValue() here.
17-
get: (property: string): unknown => getValue(appStore.getState(), property),
20+
get: (property: string): unknown => {
21+
return appStore.getState()[property as keyof AppState];
22+
},
1823
// Set a property value in the application state.
19-
set: (property: string, value: unknown) =>
20-
void appStore.setState(setValue(appStore.getState(), property, value)),
24+
set: (property: string, value: unknown) => {
25+
appStore.setState({ [property as keyof AppState]: value });
26+
},
2127
},
2228
logging: { enabled: true },
2329
});

chartlets.js/src/lib/actions/configureFramework.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ export function configureFramework(options: FrameworkOptions) {
1313
store.setState({
1414
configuration: { ...options } as FrameworkOptions,
1515
});
16+
if (options.plugins) {
17+
options.plugins.forEach((plugin) => plugin());
18+
}
1619
}

chartlets.js/src/lib/components/Plot/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

chartlets.js/src/lib/index.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
/////////////////////////////////////////////////////////////////////
2-
// The Chartlets TypeScript API
3-
41
// Types
5-
export { type Contribution } from "@/lib/types/model/contribution";
6-
export { type ContributionState } from "@/lib/types/state/contribution";
2+
export type { Contribution } from "@/lib/types/model/contribution";
3+
export type { ContributionState } from "@/lib/types/state/contribution";
74
export type {
85
ComponentState,
96
ContainerState,
107
} from "@/lib/types/state/component";
11-
export {
12-
type ComponentChangeEvent,
13-
type ComponentChangeHandler,
8+
export type {
9+
ComponentChangeEvent,
10+
ComponentChangeHandler,
1411
} from "@/lib/types/state/event";
1512
// Actions (store changes)
1613
export { initializeContributions } from "@/lib/actions/initializeContributions";
1714
export { handleComponentChange } from "@/lib/actions/handleComponentChange";
1815
export { updateContributionContainer } from "@/lib/actions/updateContributionContainer";
1916
// Component registry
20-
export { type Registry, registry } from "@/lib/component/Registry";
17+
export {
18+
type Registry,
19+
registry as componentRegistry,
20+
} from "@/lib/component/Registry";
2121
// React components
2222
export { Component } from "@/lib/component/Component";
2323
export { Children } from "@/lib/component/Children";
@@ -32,29 +32,9 @@ export {
3232
makeContributionsHook,
3333
} from "@/lib/hooks";
3434
// Application interface
35-
export { type HostStore } from "@/lib/types/state/options";
36-
37-
/////////////////////////////////////////////////////////////////////
38-
// Register standard Chartlets components that can be rendered
39-
// by the Chartlets `Component` component.
40-
// Plugins may register their own components.
41-
42-
import { registry } from "@/lib/component/Registry";
43-
44-
import { Box } from "@/lib/components/Box";
45-
import { Button } from "@/lib/components/Button";
46-
import { Checkbox } from "@/lib/components/Checkbox";
47-
import { CircularProgress } from "@/lib/components/CircularProgress";
48-
import { IconButton } from "@/lib/components/IconButton";
49-
import { Plot } from "@/lib/components/Plot";
50-
import { Select } from "@/lib/components/Select";
51-
import { Typography } from "@/lib/components/Typography";
52-
53-
registry.register("Box", Box);
54-
registry.register("Button", Button);
55-
registry.register("Checkbox", Checkbox);
56-
registry.register("CircularProgress", CircularProgress);
57-
registry.register("IconButton", IconButton);
58-
registry.register("Plot", Plot);
59-
registry.register("Select", Select);
60-
registry.register("Typography", Typography);
35+
export type {
36+
FrameworkOptions,
37+
HostStore,
38+
MutableHostStore,
39+
Plugin,
40+
} from "@/lib/types/state/options";
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)