@kanaries/graphic-walker 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { IDarkMode, IThemeKey, IComputationFunction } from '../interfaces';
3
3
  import { IReactVegaHandler } from '../vis/react-vega';
4
4
  interface RendererProps {
5
5
  themeKey?: IThemeKey;
6
+ themeConfig?: any;
6
7
  dark?: IDarkMode;
7
8
  computationFunction: IComputationFunction;
8
9
  }
@@ -3,6 +3,7 @@ import type { IDarkMode, IRow, IThemeKey, DraggableFieldState, IVisualConfig, IC
3
3
  declare const _default: ((props: {
4
4
  name?: string | undefined;
5
5
  themeKey?: IThemeKey | undefined;
6
+ themeConfig?: any;
6
7
  dark?: IDarkMode | undefined;
7
8
  visualState: DraggableFieldState;
8
9
  visualConfig: IVisualConfig;
@@ -13,6 +13,7 @@ interface SpecRendererProps {
13
13
  onChartResize?: ((width: number, height: number) => void) | undefined;
14
14
  locale?: string;
15
15
  computationFunction: IComputationFunction;
16
+ themeConfig?: any;
16
17
  }
17
18
  /**
18
19
  * Sans-store renderer of GraphicWalker.
@@ -0,0 +1,6 @@
1
+ import { IThemeKey } from "../interfaces";
2
+ export declare function useTheme(props: {
3
+ themeKey?: IThemeKey;
4
+ themeConfig?: any;
5
+ mediaTheme: 'dark' | 'light';
6
+ }): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanaries/graphic-walker",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "scripts": {
5
5
  "dev:front_end": "vite --host",
6
6
  "dev": "npm run dev:front_end",
package/src/App.tsx CHANGED
@@ -38,6 +38,7 @@ export interface IGWProps {
38
38
  fieldKeyGuard?: boolean;
39
39
  /** @default "vega" */
40
40
  themeKey?: IThemeKey;
41
+ themeConfig?: any;
41
42
  dark?: IDarkMode;
42
43
  storeRef?: React.MutableRefObject<IGlobalStore | null>;
43
44
  computation?: IComputationFunction;
@@ -67,6 +68,7 @@ const App = observer<IGWProps>(function App(props) {
67
68
  hideDataSourceConfig,
68
69
  fieldKeyGuard = true,
69
70
  themeKey = 'vega',
71
+ themeConfig,
70
72
  dark = 'media',
71
73
  computation,
72
74
  toolbar,
@@ -209,7 +211,7 @@ const App = observer<IGWProps>(function App(props) {
209
211
  // }}
210
212
  >
211
213
  {datasets.length > 0 && (
212
- <ReactiveRenderer ref={rendererRef} themeKey={themeKey} dark={dark} computationFunction={vizStore.computationFunction} />
214
+ <ReactiveRenderer ref={rendererRef} themeKey={themeKey} themeConfig={themeConfig} dark={dark} computationFunction={vizStore.computationFunction} />
213
215
  )}
214
216
  {/* {vizEmbededMenu.show && (
215
217
  <ClickMenu x={vizEmbededMenu.position[0]} y={vizEmbededMenu.position[1]}>
@@ -18,9 +18,9 @@ export function useGeoJSON(geojson?: FeatureCollection, url?: IGeoUrl) {
18
18
  .then((json) => {
19
19
  if (timestamp !== lastFetchedRef.current) return;
20
20
  if (url.type === 'GeoJSON') {
21
- data[key] = json;
21
+ GeoJSONDict[key] = json;
22
22
  } else {
23
- data[key] = feature(json, Object.keys(json.objects)[0]);
23
+ GeoJSONDict[key] = feature(json, Object.keys(json.objects)[0]) as unknown as FeatureCollection;
24
24
  }
25
25
  setLastFetched(timestamp);
26
26
  });
@@ -15,6 +15,7 @@ import { initVisualConfig } from '../utils/save';
15
15
 
16
16
  interface RendererProps {
17
17
  themeKey?: IThemeKey;
18
+ themeConfig?: any;
18
19
  dark?: IDarkMode;
19
20
  computationFunction: IComputationFunction;
20
21
  }
@@ -23,7 +24,7 @@ interface RendererProps {
23
24
  * Depending on global store.
24
25
  */
25
26
  const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, ref) {
26
- const { themeKey, dark, computationFunction } = props;
27
+ const { themeKey, dark, computationFunction, themeConfig } = props;
27
28
  const { vizStore, commonStore } = useGlobalStore();
28
29
  const {
29
30
  allFields,
@@ -131,6 +132,7 @@ const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, r
131
132
  data={viewData}
132
133
  ref={ref}
133
134
  themeKey={themeKey}
135
+ themeConfig={themeConfig}
134
136
  dark={dark}
135
137
  locale={i18n.language}
136
138
  draggableFieldState={encodings}
@@ -23,6 +23,7 @@ type IPureRendererProps =
23
23
  | {
24
24
  name?: string;
25
25
  themeKey?: IThemeKey;
26
+ themeConfig?: any;
26
27
  dark?: IDarkMode;
27
28
  visualState: DraggableFieldState;
28
29
  visualConfig: IVisualConfig;
@@ -86,7 +87,6 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps>(function
86
87
  limit: limit ?? -1,
87
88
  computationFunction: computation,
88
89
  });
89
- console.log(computation)
90
90
  // Dependencies that should not trigger effect individually
91
91
  const latestFromRef = useRef({ data });
92
92
  latestFromRef.current = { data };
@@ -9,6 +9,7 @@ import { DeepReadonly, DraggableFieldState, IDarkMode, IRow, IThemeKey, IVisualC
9
9
  import LoadingLayer from '../components/loadingLayer';
10
10
  import { useCurrentMediaTheme } from '../utils/media';
11
11
  import { builtInThemes } from '../vis/theme';
12
+ import { useTheme } from '../utils/useTheme';
12
13
 
13
14
  interface SpecRendererProps {
14
15
  name?: string;
@@ -22,13 +23,14 @@ interface SpecRendererProps {
22
23
  onChartResize?: ((width: number, height: number) => void) | undefined;
23
24
  locale?: string;
24
25
  computationFunction: IComputationFunction;
26
+ themeConfig?: any;
25
27
  }
26
28
  /**
27
29
  * Sans-store renderer of GraphicWalker.
28
30
  * This is a pure component, which means it will not depend on any global state.
29
31
  */
30
32
  const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
31
- { name, themeKey, dark, data, loading, draggableFieldState, visualConfig, onGeomClick, onChartResize, locale, computationFunction },
33
+ { name, themeKey, dark, data, loading, draggableFieldState, visualConfig, onGeomClick, onChartResize, locale, computationFunction, themeConfig: customizedThemeConfig },
32
34
  ref
33
35
  ) {
34
36
  // const { draggableFieldState, visualConfig } = vizStore;
@@ -58,7 +60,11 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
58
60
 
59
61
  const enableResize = size.mode === 'fixed' && !hasFacet && Boolean(onChartResize);
60
62
  const mediaTheme = useCurrentMediaTheme(dark);
61
- const themeConfig = builtInThemes[themeKey ?? 'vega']?.[mediaTheme];
63
+ const themeConfig = useTheme({
64
+ themeKey,
65
+ mediaTheme,
66
+ themeConfig: customizedThemeConfig
67
+ })
62
68
 
63
69
  const vegaConfig = useMemo<VegaGlobalConfig>(() => {
64
70
  const config: VegaGlobalConfig = {
@@ -0,0 +1,8 @@
1
+ import { IThemeKey } from "../interfaces";
2
+ import { builtInThemes } from "../vis/theme";
3
+
4
+ export function useTheme (props: { themeKey?: IThemeKey; themeConfig?: any; mediaTheme: 'dark' | 'light' }) {
5
+ const { themeConfig, themeKey, mediaTheme } = props;
6
+ const config = (themeConfig ?? builtInThemes[themeKey ?? 'vega'])?.[mediaTheme];
7
+ return config
8
+ }