@kanaries/graphic-walker 0.4.5 → 0.4.7
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.
- package/dist/App.d.ts +1 -0
- package/dist/graphic-walker.es.js +7906 -7895
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +115 -115
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/renderer/index.d.ts +1 -0
- package/dist/renderer/pureRenderer.d.ts +1 -0
- package/dist/renderer/specRenderer.d.ts +1 -0
- package/dist/utils/useTheme.d.ts +6 -0
- package/package.json +1 -1
- package/src/App.tsx +3 -1
- package/src/hooks/service.ts +2 -2
- package/src/renderer/index.tsx +3 -1
- package/src/renderer/pureRenderer.tsx +11 -22
- package/src/renderer/specRenderer.tsx +8 -2
- package/src/utils/useTheme.ts +8 -0
package/dist/renderer/index.d.ts
CHANGED
|
@@ -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;
|
package/package.json
CHANGED
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]}>
|
package/src/hooks/service.ts
CHANGED
|
@@ -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
|
-
|
|
21
|
+
GeoJSONDict[key] = json;
|
|
22
22
|
} else {
|
|
23
|
-
|
|
23
|
+
GeoJSONDict[key] = feature(json, Object.keys(json.objects)[0]) as unknown as FeatureCollection;
|
|
24
24
|
}
|
|
25
25
|
setLastFetched(timestamp);
|
|
26
26
|
});
|
package/src/renderer/index.tsx
CHANGED
|
@@ -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}
|
|
@@ -3,17 +3,9 @@ import { unstable_batchedUpdates } from 'react-dom';
|
|
|
3
3
|
import { toJS } from 'mobx';
|
|
4
4
|
import { observer } from 'mobx-react-lite';
|
|
5
5
|
import { ShadowDom } from '../shadow-dom';
|
|
6
|
-
import LeafletRenderer from '../components/leafletRenderer';
|
|
6
|
+
import LeafletRenderer, { LEAFLET_DEFAULT_HEIGHT, LEAFLET_DEFAULT_WIDTH } from '../components/leafletRenderer';
|
|
7
7
|
import { withAppRoot } from '../components/appRoot';
|
|
8
|
-
import type {
|
|
9
|
-
IDarkMode,
|
|
10
|
-
IViewField,
|
|
11
|
-
IRow,
|
|
12
|
-
IThemeKey,
|
|
13
|
-
DraggableFieldState,
|
|
14
|
-
IVisualConfig,
|
|
15
|
-
IComputationFunction,
|
|
16
|
-
} from '../interfaces';
|
|
8
|
+
import type { IDarkMode, IViewField, IRow, IThemeKey, DraggableFieldState, IVisualConfig, IComputationFunction } from '../interfaces';
|
|
17
9
|
import type { IReactVegaHandler } from '../vis/react-vega';
|
|
18
10
|
import SpecRenderer from './specRenderer';
|
|
19
11
|
import { useRenderer } from './hooks';
|
|
@@ -23,6 +15,7 @@ type IPureRendererProps =
|
|
|
23
15
|
| {
|
|
24
16
|
name?: string;
|
|
25
17
|
themeKey?: IThemeKey;
|
|
18
|
+
themeConfig?: any;
|
|
26
19
|
dark?: IDarkMode;
|
|
27
20
|
visualState: DraggableFieldState;
|
|
28
21
|
visualConfig: IVisualConfig;
|
|
@@ -31,11 +24,11 @@ type IPureRendererProps =
|
|
|
31
24
|
locale?: string;
|
|
32
25
|
} & (
|
|
33
26
|
| {
|
|
34
|
-
type: 'remote'
|
|
27
|
+
type: 'remote';
|
|
35
28
|
computation: IComputationFunction;
|
|
36
29
|
}
|
|
37
30
|
| {
|
|
38
|
-
type?: 'local'
|
|
31
|
+
type?: 'local';
|
|
39
32
|
rawData: IRow[];
|
|
40
33
|
}
|
|
41
34
|
);
|
|
@@ -51,7 +44,7 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps>(function
|
|
|
51
44
|
return props.computation;
|
|
52
45
|
}
|
|
53
46
|
return getComputation(props.rawData);
|
|
54
|
-
}, [props.type, props.type === 'remote' ? props.computation: props.rawData])
|
|
47
|
+
}, [props.type, props.type === 'remote' ? props.computation : props.rawData]);
|
|
55
48
|
const defaultAggregated = visualConfig?.defaultAggregated ?? false;
|
|
56
49
|
|
|
57
50
|
const [viewData, setViewData] = useState<IRow[]>([]);
|
|
@@ -86,7 +79,6 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps>(function
|
|
|
86
79
|
limit: limit ?? -1,
|
|
87
80
|
computationFunction: computation,
|
|
88
81
|
});
|
|
89
|
-
console.log(computation)
|
|
90
82
|
// Dependencies that should not trigger effect individually
|
|
91
83
|
const latestFromRef = useRef({ data });
|
|
92
84
|
latestFromRef.current = { data };
|
|
@@ -103,15 +95,12 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps>(function
|
|
|
103
95
|
const isSpatial = coordSystem === 'geographic';
|
|
104
96
|
|
|
105
97
|
return (
|
|
106
|
-
<ShadowDom>
|
|
107
|
-
<div className="relative">
|
|
98
|
+
<ShadowDom className="flex w-full" style={{ height: '100%' }}>
|
|
99
|
+
<div className="relative flex flex-col w-full flex-1">
|
|
108
100
|
{isSpatial && (
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
draggableFieldState={visualState}
|
|
113
|
-
visualConfig={visualConfig}
|
|
114
|
-
/>
|
|
101
|
+
<div className="max-w-full" style={{ width: LEAFLET_DEFAULT_WIDTH, height: LEAFLET_DEFAULT_HEIGHT, flexGrow: 1 }}>
|
|
102
|
+
<LeafletRenderer data={data} draggableFieldState={visualState} visualConfig={visualConfig} />
|
|
103
|
+
</div>
|
|
115
104
|
)}
|
|
116
105
|
{isSpatial || (
|
|
117
106
|
<SpecRenderer
|
|
@@ -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 =
|
|
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
|
+
}
|