Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: facet issue (#187)

islxyqwe382c7d1cddd9
diff --git a/packages/graphic-walker/package.json b/packages/graphic-walker/package.json
index d0f5cec3..267912dc 100644
--- a/packages/graphic-walker/package.json
+++ b/packages/graphic-walker/package.json
@@ -35,6 +35,7 @@
},
"types": "./dist/index.d.ts",
"dependencies": {
+ "@headlessui-float/react": "^0.11.4",
"@headlessui/react": "^1.7.12",
"@heroicons/react": "^2.0.8",
"@kanaries/react-beautiful-dnd": "^0.0.3",
@@ -65,8 +66,8 @@
"react-shadow": "^20.0.0",
"rxjs": "^7.3.0",
"tailwindcss": "^3.2.4",
- "ts-jest": "^29.1.1",
"topojson-client": "^3.1.0",
+ "ts-jest": "^29.1.1",
"vega": "^5.22.1",
"vega-embed": "^6.21.0",
"vega-lite": "^5.6.0"
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsx
index 015d3c24..28caf60d 100644
--- a/packages/graphic-walker/src/App.tsx
+++ b/packages/graphic-walker/src/App.tsx
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useRef, useCallback } from 'react';
import { observer } from 'mobx-react-lite';
import { useTranslation } from 'react-i18next';
import { LightBulbIcon } from "@heroicons/react/24/outline";
-import { IGeographicData, IComputationFunction, ISegmentKey, IThemeKey, IMutField, IGeoDataItem, VegaGlobalConfig, IChannelScales } from './interfaces';
+import { IGeographicData, IComputationFunction, ISegmentKey, IThemeKey, IMutField, IGeoDataItem, VegaGlobalConfig, IChannelScales, Specification, IDarkMode } from './interfaces';
import type { IReactVegaHandler } from './vis/react-vega';
import VisualSettings from './visualSettings';
import PosFields from './fields/posFields';
@@ -22,7 +22,7 @@ import GeoConfigPanel from './components/leafletRenderer/geoConfigPanel';
import type { ToolbarItemProps } from './components/toolbar';
import ClickMenu from './components/clickMenu';
import AskViz from './components/askViz';
-import { VizSpecStore } from './store/visualSpecStore';
+import { VizSpecStore, renderSpec } from './store/visualSpecStore';
import FieldsContextWrapper from './fields/fieldsContext';
import { guardDataKeys } from './utils/dataPrep';
import { getComputation } from './computation/clientComputation';
@@ -32,6 +32,7 @@ import { ErrorContext } from './utils/reportError';
import { ErrorBoundary } from 'react-error-boundary';
import Errorpanel from './components/errorpanel';
import { GWGlobalConfig } from './vis/theme';
+import { useCurrentMediaTheme } from './utils/media';
export interface BaseVizProps {
i18nLang?: string;
@@ -58,6 +59,7 @@ export interface BaseVizProps {
onError?: (err: Error) => void;
geoList?: IGeoDataItem[];
channelScales?: IChannelScales;
+ spec?: Specification;
}
export const VizApp = observer(function VizApp(props: BaseVizProps) {
@@ -72,6 +74,8 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
toolbar,
geographicData,
computationTimeout = 60000,
+ spec,
+ onError
} = props;
const { t, i18n } = useTranslation();
@@ -92,10 +96,16 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
const vizStore = useVizStore();
useEffect(() => {
- if (props.geographicData) {
- vizStore.setGeographicData(props.geographicData, props.geographicData.key);
+ if (geographicData) {
+ vizStore.setGeographicData(geographicData, geographicData.key);
}
- }, [geographicData]);
+ }, [vizStore, geographicData]);
+
+ useEffect(() => {
+ if (spec) {
+ vizStore.replaceNow(renderSpec(spec, vizStore.meta, vizStore.currentVis.name ?? 'Chart 1', vizStore.currentVis.visId));
+ }
+ }, [spec, vizStore]);
const rendererRef = useRef<IReactVegaHandler>(null);
@@ -105,12 +115,12 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
(msg: string, code?: number) => {
const err = new Error(`Error${code ? `(${code})` : ''}: ${msg}`);
console.error(err);
- props.onError?.(err);
+ onError?.(err);
if (code) {
vizStore.updateShowErrorResolutionPanel(code);
}
},
- [vizStore, props.onError]
+ [vizStore, onError]
);
const { segmentKey, vizEmbededMenu } = vizStore;
@@ -215,12 +225,16 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
export type VizProps = {
i18nLang?: string;
i18nResources?: { [lang: string]: Record<string, string | any> };
+ themeConfig?: GWGlobalConfig;
themeKey?: IThemeKey;
- darkMode?: 'light' | 'dark';
+ dark?: IDarkMode;
toolbar?: {
extra?: ToolbarItemProps[];
exclude?: string[];
};
+ geographicData?: IGeographicData & {
+ key: string;
+ };
enhanceAPI?: {
header?: Record<string, string>;
features?: {
@@ -232,6 +246,11 @@ export type VizProps = {
rawFields: IMutField[];
onMetaChange?: (fid: string, meta: Partial<IMutField>) => void;
computationTimeout?: number;
+ dataSelection?: React.ReactChild;
+ onError?: (err: Error) => void;
+ geoList?: IGeoDataItem[];
+ channelScales?: IChannelScales;
+ spec?: Specification;
} & (
| {
/**
@@ -268,20 +287,31 @@ export function VizAppWithContext(props: VizProps) {
};
}, [props.rawFields, props.dataSource ? props.dataSource : props.computation, props.fieldKeyGuard]);
+ const darkMode = useCurrentMediaTheme(props.dark);
+
return (
- <VizStoreWrapper onMetaChange={props.onMetaChange} meta={safeMetas} keepAlive={props.keepAlive} storeRef={props.storeRef}>
- <FieldsContextWrapper>
- <VizApp
- darkMode={props.darkMode}
- enhanceAPI={props.enhanceAPI}
- i18nLang={props.i18nLang}
- i18nResources={props.i18nResources}
- themeKey={props.themeKey}
- toolbar={props.toolbar}
- computation={computation}
- computationTimeout={props.computationTimeout}
- />
- </FieldsContextWrapper>
- </VizStoreWrapper>
+ <div className={`${darkMode === 'dark' ? 'dark' : ''} App font-sans bg-white dark:bg-zinc-900 dark:text-white m-0 p-0`}>
+ <VizStoreWrapper onMetaChange={props.onMetaChange} meta={safeMetas} keepAlive={props.keepAlive} storeRef={props.storeRef}>
+ <FieldsContextWrapper>
+ <VizApp
+ darkMode={darkMode}
+ enhanceAPI={props.enhanceAPI}
+ i18nLang={props.i18nLang}
+ i18nResources={props.i18nResources}
+ themeKey={props.themeKey}
+ toolbar={props.toolbar}
+ computation={computation}
+ computationTimeout={props.computationTimeout}
+ channelScales={props.channelScales}
+ dataSelection={props.dataSelection}
+ geoList={props.geoList}
+ geographicData={props.geographicData}
+ onError={props.onError}
+ spec={props.spec}
+ themeConfig={props.themeConfig}
+ />
+ </FieldsContextWrapper>
+ </VizStoreWrapper>
+ </div>
);
}
diff --git a/packages/graphic-walker/src/FullApp.tsx b/packages/graphic-walker/src/FullApp.tsx
index bae8a3a2..863901df 100644
--- a/packages/graphic-walker/src/FullApp.tsx
+++ b/packages/graphic-walker/src/FullApp.tsx
@@ -8,14 +8,15 @@ import type { ToolbarItemProps } from './components/toolbar';
import { VizApp } from './App';
import { CommonStore } from './store/commonStore';
import FieldsContextWrapper from './fields/fieldsContext';
+import { GWGlobalConfig } from './vis/theme';
export interface IGWProps {
- hideDataSourceConfig?: boolean;
i18nLang?: string;
i18nResources?: { [lang: string]: Record<string, string | any> };
keepAlive?: boolean | string;
/** @default "vega" */
themeKey?: IThemeKey;
+ themeConfig?: GWGlobalConfig;
dark?: IDarkMode;
toolbar?: {
extra?: ToolbarItemProps[];
@@ -37,7 +38,7 @@ export interface IGWProps {
}
export const AppContent = observer<Omit<IGWProps, 'storeRef' | 'keepAlive'>>(function App(props) {
- const { i18nLang = 'en-US', i18nResources, themeKey = 'vega', dark = 'media', toolbar, enhanceAPI } = props;
+ const { i18nLang = 'en-US', i18nResources, themeKey = 'vega', dark = 'media', themeConfig, toolbar, enhanceAPI, geographicData, onError, geoList, channelScales } = props;
const commonStore = useGlobalStore();
const { dataStore } = commonStore;
@@ -56,7 +57,12 @@ export const AppContent = observer<Omit<IGWProps, 'storeRef' | 'keepAlive'>>(fun
i18nLang={i18nLang}
i18nResources={i18nResources}
themeKey={themeKey}
+ themeConfig={themeConfig}
toolbar={toolbar}
+ geographicData={geographicData}
+ geoList={geoList}
+ onError={onError}
+ channelScales={channelScales}
/>
</div>
</FieldsContextWrapper>
diff --git a/packages/graphic-walker/src/components/askViz/index.tsx b/packages/graphic-walker/src/components/askViz/index.tsx
index e80af259..40bb7442 100644
--- a/packages/graphic-walker/src/components/askViz/index.tsx
+++ b/packages/graphic-walker/src/components/askViz/index.tsx
@@ -57,7 +57,7 @@ const AskViz: React.FC<{ api?: string; headers?: Record<string, string> }> = (pr
.finally(() => {
setLoading(false);
});
- }, [query, allFields]);
+ }, [props.api, props.headers, allFields, query, vizStore]);
return (
<div className="right-0 flex">
<input
diff --git a/packages/graphic-walker/src/components/codeExport/index.tsx b/packages/graphic-walker/src/components/codeExport/index.tsx
index 6e879b31..0ee2ee94 100644
--- a/packages/graphic-walker/src/components/codeExport/index.tsx
+++ b/packages/graphic-walker/src/components/codeExport/index.tsx
@@ -66,7 +66,7 @@ const CodeExport: React.FC = observer((props) => {
setCode("vega code");
}
}
- }, [tabKey, showCodeExportPanel]);
+ }, [tabKey, showCodeExportPanel, vizStore]);
return (
<Modal
show={showCodeExportPanel}
diff --git a/packages/graphic-walker/src/components/pivotTable/index.tsx b/packages/graphic-walker/src/components/pivotTable/index.tsx
index 1a6ade1e..18669ab3 100644
--- a/packages/graphic-walker/src/components/pivotTable/index.tsx
+++ b/packages/graphic-walker/src/components/pivotTable/index.tsx
@@ -5,6 +5,7 @@ import { dataQuery } from '../../computation';
import { useAppRootContext } from '../../components/appRoot';
import LeftTree from './leftTree';
import TopTree from './topTree';
+import { observer } from 'mobx-react-lite';
import {
DeepReadonly,
DraggableFieldState,
@@ -34,7 +35,7 @@ interface PivotTableProps {
const emptyMap = new Map();
-const PivotTable: React.FC<PivotTableProps> = function PivotTableComponent(props) {
+const PivotTable: React.FC<PivotTableProps> = observer(function PivotTableComponent(props) {
const { data, visualConfig, loading, layout, draggableFieldState } = props;
const computation = useCompututaion();
const appRef = useAppRootContext();
@@ -85,7 +86,7 @@ const PivotTable: React.FC<PivotTableProps> = function PivotTableComponent(props
} else {
aggregateThenGenerate();
}
- }, [data, enableCollapse]);
+ }, [data, enableCollapse, vizStore]);
useEffect(() => {
if (!enableCollapse || showTableSummary) {
@@ -233,6 +234,6 @@ const PivotTable: React.FC<PivotTableProps> = function PivotTableComponent(props
</div>
</div>
);
-};
+});
export default PivotTable;
diff --git a/packages/graphic-walker/src/components/selectContext/index.tsx b/packages/graphic-walker/src/components/selectContext/index.tsx
index 8a99450b..492506af 100644
--- a/packages/graphic-walker/src/components/selectContext/index.tsx
+++ b/packages/graphic-walker/src/components/selectContext/index.tsx
@@ -1,6 +1,7 @@
import React, { Fragment, useEffect, useRef, useState } from 'react';
import { Listbox, Transition } from '@headlessui/react';
import { CheckIcon, Cog6ToothIcon } from '@heroicons/react/24/outline';
+import { Float } from '@headlessui-float/react';
export interface ISelectContextOption {
key: string;
@@ -43,7 +44,7 @@ const SelectContext: React.FC<ISelectContextProps> = (props) => {
return (
<Listbox multiple value={selected} onChange={setSelected}>
- <div className={`relative ${className}`}>
+ <Float as="div" className={className}>
<div className="relative w-full flex items-center space-x-2">
<span className="flex-1 block truncate text-start">{props.children}</span>
<Listbox.Button className="grow-0 shrink-0 flex items-center relative">
@@ -85,7 +86,7 @@ const SelectContext: React.FC<ISelectContextProps> = (props) => {
))}
</Listbox.Options>
</Transition>
- </div>
+ </Float>
</Listbox>
);
};
diff --git a/packages/graphic-walker/src/components/tabs/editableTab.tsx b/packages/graphic-walker/src/components/tabs/editableTab.tsx
index 7c775387..9c6504b5 100644
--- a/packages/graphic-walker/src/components/tabs/editableTab.tsx
+++ b/packages/graphic-walker/src/components/tabs/editableTab.tsx
@@ -27,66 +27,69 @@ interface EditableTabsProps {
onRemove?: (index: number) => void;
}
-const Slider = (props: { className?: string; children: React.ReactNode; safeDistance: number }) => {
+const Slider = (props: { className?: string; children: React.ReactNode }) => {
const [x, setX] = useState(0);
const ref = useRef<HTMLDivElement>();
+ const parentDisposeRef = useRef<() => void>();
const childDisposeRef = useRef<() => void>();
- const onWheel = useCallback(
- (e: WheelEvent) => {
- e.preventDefault();
- e.stopPropagation();
- const rect = ref.current?.children[0]?.getBoundingClientRect();
- if (rect) {
- setX((x) => Math.min(rect.width - props.safeDistance, Math.max(0, x + e.deltaY)));
- }
- return false;
- },
- [props.safeDistance]
- );
+ const onWheel = useCallback((e: WheelEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ const parentWidth = ref.current?.getBoundingClientRect().width;
+ const childWidth = ref.current?.children[0]?.getBoundingClientRect().width;
+ if (parentWidth && childWidth) {
+ setX((x) => Math.min(Math.max(0, childWidth - parentWidth), Math.max(0, x + e.deltaY + e.deltaX)));
+ }
+ return false;
+ }, []);
const refCB = useCallback(
(node) => {
+ parentDisposeRef.current?.();
if (node == null) {
- if (ref.current != null) {
- ref.current.removeEventListener('wheel', onWheel);
- }
- return;
- }
- ref.current = node;
- node.addEventListener('wheel', onWheel, { passive: false });
- },
- [onWheel]
- );
-
- const onResize = useCallback(
- (rect) => {
- setX((x) => Math.min(x, rect.width - props.safeDistance));
- },
- [props.safeDistance]
- );
-
- const childRefCB = useCallback(
- (node) => {
- if (node === null) {
- if (childDisposeRef.current != null) {
- childDisposeRef.current();
- }
return;
}
const r = new ResizeObserver((es) => {
for (const e of es) {
- onResize(e.contentRect);
+ const parentWidth = e.contentRect.width;
+ const childWidth = ref.current?.children[0]?.getBoundingClientRect().width;
+ if (parentWidth && childWidth) {
+ setX((x) => Math.min(Math.max(0, childWidth - parentWidth), x));
+ }
}
});
- childDisposeRef.current = () => {
+ r.observe(node);
+ ref.current = node;
+ node.addEventListener('wheel', onWheel, { passive: false });
+ parentDisposeRef.current = () => {
r.disconnect();
+ ref.current?.removeEventListener('wheel', onWheel);
};
- r.observe(node);
},
- [onResize]
+ [onWheel]
);
+ const childRefCB = useCallback((node: HTMLDivElement) => {
+ childDisposeRef.current?.();
+ if (node === null) {
+ return;
+ }
+ const r = new ResizeObserver((es) => {
+ for (const e of es) {
+ const parentWidth = ref.current?.getBoundingClientRect().width;
+ const childWidth = e.contentRect.width;
+ if (parentWidth && childWidth) {
+ setX((x) => Math.min(Math.max(0, childWidth - parentWidth), x));
+ }
+ }
+ });
+ childDisposeRef.current = () => {
+ r.disconnect();
+ };
+ r.observe(node);
+ }, []);
+
return (
<div
style={{ overflowX: 'clip' }}
@@ -159,7 +162,7 @@ export default function EditableTabs(props: EditableTabsProps) {
</div>
</div>
</Modal>
- <Slider safeDistance={120}>
+ <Slider>
<nav className="-mb-px flex h-8 border-gray-200 dark:border-gray-700" role="tablist" aria-label="Tabs">
{tabs.map((tab, tabIndex) => (
<span
@@ -174,15 +177,15 @@ export default function EditableTabs(props: EditableTabsProps) {
key={tab.key}
className={classNames(
tab.key === selectedKey
- ? 'border rounded-t'
+ ? 'border'
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 hover:bg-gray-50 dark:hover:text-gray-200 dark:hover:bg-gray-800',
- 'flex whitespace-nowrap group border-gray-200 dark:border-gray-700 py-1 px-2 pr-2 text-sm cursor-default dark:text-white'
+ 'flex whitespace-nowrap rounded-t group border-gray-200 dark:border-gray-700 py-1 px-2 pr-2 text-sm cursor-default dark:text-white'
)}
>
{tab.label}
{tab.key === selectedKey && tab.editable && (
<Popover className="relative inline-flex">
- <Popover.Button className="inline-flex items-center gap-x-1 text-sm font-semibold leading-6 text-gray-900">
+ <Popover.Button className="inline-flex items-center gap-x-1 text-sm font-semibold leading-6 text-gray-900 dark:text-white">
<EllipsisVerticalIcon className="h-4 w-4" aria-hidden="true" />
</Popover.Button>
<Transition
@@ -195,7 +198,7 @@ export default function EditableTabs(props: EditableTabsProps) {
leaveTo="opacity-0 translate-y-1"
>
<Popover.Panel className="absolute left-1/2 z-10 mt-5 flex w-screen max-w-min -translate-x-1/4 px-2">
- <div className="shrink rounded p-1 bg-white text-xs font-semibold leading-2 text-gray-900 shadow-lg ring-1 ring-gray-900/5">
+ <div className="shrink rounded p-1 bg-white dark:bg-zinc-900 text-xs font-semibold leading-2 text-gray-900 dark:text-white shadow-lg ring-1 ring-gray-900/5">
<button
onClick={(e) => {
e.stopPropagation();
@@ -204,7 +207,7 @@ export default function EditableTabs(props: EditableTabsProps) {
setName(tab.label);
});
}}
- className="block p-1 w-full hover:bg-gray-200 text-left"
+ className="block p-1 w-full hover:bg-gray-200 dark:hover:bg-gray-800 text-left"
>
{'Edit'}
</button>
@@ -213,7 +216,7 @@ export default function EditableTabs(props: EditableTabsProps) {
e.stopPropagation();
onDuplicate?.(tabIndex);
}}
- className="block p-1 w-full hover:bg-gray-200 text-left"
+ className="block p-1 w-full hover:bg-gray-200 dark:hover:bg-gray-800 text-left"
>
{'Duplicate'}
</button>
@@ -223,7 +226,7 @@ export default function EditableTabs(props: EditableTabsProps) {
e.stopPropagation();
onRemove?.(tabIndex);
}}
- className="block p-1 w-full hover:bg-gray-200 text-red-500 text-left"
+ className="block p-1 w-full hover:bg-gray-200 dark:hover:bg-gray-800 text-red-500 text-left"
>
{'Remove'}
</button>
@@ -239,4 +242,4 @@ export default function EditableTabs(props: EditableTabsProps) {
</Slider>
</div>
);
-}
\ No newline at end of file
+}
diff --git a/packages/graphic-walker/src/components/visualConfig/index.tsx b/packages/graphic-walker/src/components/visualConfig/index.tsx
index 15c86b69..ac8e9267 100644
--- a/packages/graphic-walker/src/components/visualConfig/index.tsx
+++ b/packages/graphic-walker/src/components/visualConfig/index.tsx
@@ -1,6 +1,6 @@
import React, { useEffect, useState, useMemo, useCallback } from 'react';
import { observer } from 'mobx-react-lite';
-import { runInAction, toJS } from 'mobx';
+import { runInAction } from 'mobx';
import { useTranslation } from 'react-i18next';
import { SketchPicker } from 'react-color';
@@ -36,7 +36,7 @@ function useScale(minRange: number, maxRange: number, defaultMinRange?: number,
setDomainMax(value.domainMax ?? 100);
setRangeMax(value.rangeMax ?? defaultMaxRange ?? maxRange);
setRangeMin(value.rangeMin ?? defaultMinRange ?? minRange);
- }, []);
+ }, [defaultMaxRange, defaultMinRange, maxRange, minRange]);
const value = useMemo(
() => ({
@@ -67,14 +67,9 @@ function useScale(minRange: number, maxRange: number, defaultMinRange?: number,
};
}
-const VisualConfigPanel: React.FC = (props) => {
+const VisualConfigPanel: React.FC = () => {
const vizStore = useVizStore();
- const { config, layout, showVisualConfigPanel } = vizStore;
- const {
- coordSystem,
- geoms: [markType],
- } = config;
- const isChoropleth = coordSystem === 'geographic' && markType === 'choropleth';
+ const { layout, showVisualConfigPanel } = vizStore;
const { t } = useTranslation();
const formatConfigList: (keyof IVisualConfig['format'])[] = ['numberFormat', 'timeFormat', 'normalizedNumberFormat'];
const [format, setFormat] = useState<IVisualConfig['format']>({
@@ -158,7 +153,7 @@ const VisualConfigPanel: React.FC = (props) => {
<SketchPicker
presetColors={DEFAULT_COLOR_SCHEME}
color={defaultColor}
- onChange={(color, event) => {
+ onChange={(color) => {
setColorEdited(true);
setDefaultColor({
...color.rgb,
diff --git a/packages/graphic-walker/src/computation/index.ts b/packages/graphic-walker/src/computation/index.ts
index 79f42493..5f8d6bf8 100644
--- a/packages/graphic-walker/src/computation/index.ts
+++ b/packages/graphic-walker/src/computation/index.ts
@@ -197,5 +197,5 @@ export async function getTemporalRange(service: IComputationFunction, field: str
[MAX_ID]: 0,
},
] = await service(rangeQueryPayload);
- return [rangeRes[MIN_ID], rangeRes[MAX_ID]] as [number, number];
+ return [new Date(rangeRes[MIN_ID]).getTime(), new Date(rangeRes[MAX_ID]).getTime()] as [number, number];
}
diff --git a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx
index da25f5cb..c92271fd 100644
--- a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx
+++ b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx
@@ -29,7 +29,7 @@ const CSVData: React.FC<ICSVData> = (props) => {
const onSubmitData = useCallback(() => {
commonStore.commitTempDS();
- }, []);
+ }, [commonStore]);
const { t } = useTranslation('translation', { keyPrefix: 'DataSource.dialog.file' });
const fileLoaded = tmpDataSource.length > 0 && tmpDSRawFields.length > 0;
@@ -55,7 +55,7 @@ const CSVData: React.FC<ICSVData> = (props) => {
}
}
},
- [fileType, encoding]
+ [commonStore, fileType, encoding]
);
return (
diff --git a/packages/graphic-walker/src/fields/aestheticFields.tsx b/packages/graphic-walker/src/fields/aestheticFields.tsx
index 5b37f64e..33a489c8 100644
--- a/packages/graphic-walker/src/fields/aestheticFields.tsx
+++ b/packages/graphic-walker/src/fields/aestheticFields.tsx
@@ -42,7 +42,7 @@ const AestheticFields: React.FC = (props) => {
return (
<div>
{channels.map((dkey, i, { length }) => (
- <AestheticFieldContainer name={dkey.id} key={dkey.id} style={{ position: 'relative', zIndex: length - i }}>
+ <AestheticFieldContainer name={dkey.id} key={dkey.id} style={{ position: 'relative' }}>
<Droppable droppableId={dkey.id} direction="horizontal">
{(provided, snapshot) => (
// <OBFieldContainer dkey={dkey} provided={provided} />
diff --git a/packages/graphic-walker/src/fields/components.tsx b/packages/graphic-walker/src/fields/components.tsx
index eec0b6b5..4fedd325 100644
--- a/packages/graphic-walker/src/fields/components.tsx
+++ b/packages/graphic-walker/src/fields/components.tsx
@@ -80,7 +80,6 @@ export const FieldListSegment = styled.div`
div.fl-container {
flex-grow: 10;
position: relative;
- z-index: 1;
}
`;
diff --git a/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx b/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx
index c0242e0d..dcec0d3a 100644
--- a/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx
+++ b/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx
@@ -50,13 +50,9 @@ const SingleEncodeEditor: React.FC<SingleEncodeEditorProps> = (props) => {
return (
<div className="p-1 select-none relative" {...provided.droppableProps} ref={provided.innerRef}>
<div
-
className={`p-1.5 bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 flex item-center justify-center grow text-gray-500 dark:text-gray-400 ${
-
- (channelItem && !snapshot.draggingFromThisWith) || snapshot.isDraggingOver ? 'opacity-0' : 'opacity-100'
-
+ snapshot.draggingFromThisWith || snapshot.isDraggingOver || !channelItem ? 'opacity-100' : 'opacity-0'
} relative z-0`}
-
>
{t('actions.drop_field')}
</div>
@@ -68,7 +64,7 @@ const SingleEncodeEditor: React.FC<SingleEncodeEditorProps> = (props) => {
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
- className="flex items-stretch absolute z-10 top-0 left-0 right-0 bottom-0 m-1"
+ className={"flex items-stretch absolute top-0 left-0 right-0 bottom-0 m-1" + (provided.draggableProps.style?.transform ? ' z-10' : '')}
>
<div
onClick={() => {
diff --git a/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx b/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx
index 81e12477..eef13ff4 100644
--- a/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx
+++ b/packages/graphic-walker/src/fields/filterField/filterEditDialog.tsx
@@ -69,7 +69,7 @@ const FilterEditDialog: React.FC = observer(() => {
}
vizStore.closeFilterEditing();
- }, [editingFilterIdx, uncontrolledField]);
+ }, [editingFilterIdx, uncontrolledField?.rule, vizStore]);
const allFieldOptions = React.useMemo(() => {
return allFields.map((d) => ({
diff --git a/packages/graphic-walker/src/fields/posFields/index.tsx b/packages/graphic-walker/src/fields/posFields/index.tsx
index 741059cf..15b7dfdf 100644
--- a/packages/graphic-walker/src/fields/posFields/index.tsx
+++ b/packages/graphic-walker/src/fields/posFields/index.tsx
@@ -6,9 +6,6 @@ import { FieldListContainer } from '../components';
import { DRAGGABLE_STATE_KEYS } from '../fieldsContext';
import OBFieldContainer from '../obComponents/obFContainer';
-const firstChannelStyle = {
- zIndex: 2,
-};
import { IDraggableViewStateKey } from '../../interfaces';
const PosFields: React.FC = (props) => {
@@ -31,7 +28,7 @@ const PosFields: React.FC = (props) => {
return (
<div>
{channels.map((dkey, i) => (
- <FieldListContainer name={dkey.id} key={dkey.id} style={i === 0 ? firstChannelStyle : undefined}>
+ <FieldListContainer name={dkey.id} key={dkey.id}>
<Droppable droppableId={dkey.id} direction="horizontal">
{(provided, snapshot) => <OBFieldContainer dkey={dkey} provided={provided} />}
</Droppable>
diff --git a/packages/graphic-walker/src/index.tsx b/packages/graphic-walker/src/index.tsx
index e8809b47..49f9e225 100644
--- a/packages/graphic-walker/src/index.tsx
+++ b/packages/graphic-walker/src/index.tsx
@@ -4,16 +4,14 @@ import { observer } from 'mobx-react-lite';
import { VizAppWithContext, VizProps } from './App';
import { App, IGWProps } from './FullApp';
-import { StoreWrapper } from './store/index';
import { ShadowDom } from './shadow-dom';
import AppRoot from './components/appRoot';
import type { IGWHandler, IGWHandlerInsider } from './interfaces';
import './empty_sheet.css';
-export const GraphicWalker = observer(
+export const FullGraphicWalker = observer(
forwardRef<IGWHandler, IGWProps>((props, ref) => {
- const { storeRef } = props;
const [shadowRoot, setShadowRoot] = useState<ShadowRoot | null>(null);
const handleMount = (shadowRoot: ShadowRoot) => {
@@ -24,20 +22,18 @@ export const GraphicWalker = observer(
};
return (
- <StoreWrapper keepAlive={props.keepAlive} storeRef={storeRef}>
- <AppRoot ref={ref as ForwardedRef<IGWHandlerInsider>}>
- <ShadowDom onMount={handleMount} onUnmount={handleUnmount}>
- <DOMProvider value={{ head: shadowRoot ?? document.head, body: shadowRoot ?? document.body }}>
- <App {...props} />
- </DOMProvider>
- </ShadowDom>
- </AppRoot>
- </StoreWrapper>
+ <AppRoot ref={ref as ForwardedRef<IGWHandlerInsider>}>
+ <ShadowDom onMount={handleMount} onUnmount={handleUnmount}>
+ <DOMProvider value={{ head: shadowRoot ?? document.head, body: shadowRoot ?? document.body }}>
+ <App {...props} />
+ </DOMProvider>
+ </ShadowDom>
+ </AppRoot>
);
})
);
-export const SimpleGraphicWalker = observer(
+export const GraphicWalker = observer(
forwardRef<IGWHandler, VizProps>((props, ref) => {
const [shadowRoot, setShadowRoot] = useState<ShadowRoot | null>(null);
@@ -68,4 +64,4 @@ export { resolveChart, convertChart } from './models/visSpecHistory';
export { getGlobalConfig } from './config';
export { getComputation } from './computation/clientComputation';
-export { addFilterForQuery } from './utils/workflow';
\ No newline at end of file
+export { addFilterForQuery } from './utils/workflow';
diff --git a/packages/graphic-walker/src/models/visSpecHistory.ts b/packages/graphic-walker/src/models/visSpecHistory.ts
index 5bc17275..dbf03dbc 100644
--- a/packages/graphic-walker/src/models/visSpecHistory.ts
+++ b/packages/graphic-walker/src/models/visSpecHistory.ts
@@ -53,8 +53,8 @@ type PropsMap = {
[Methods.setConfig]: KVTuple<IVisualConfigNew>;
[Methods.removeField]: [keyof DraggableFieldState, number];
[Methods.reorderField]: [keyof DraggableFieldState, number, number];
- [Methods.moveField]: [normalKeys, number, normalKeys, number];
- [Methods.cloneField]: [normalKeys, number, normalKeys, number, string];
+ [Methods.moveField]: [normalKeys, number, normalKeys, number, number | null];
+ [Methods.cloneField]: [normalKeys, number, normalKeys, number, string, number | null];
[Methods.createBinlogField]: [normalKeys, number, 'bin' | 'binCount' | 'log10' | 'log2' | 'log', string, number];
[Methods.appendFilter]: [number, normalKeys, number, string];
[Methods.modFilter]: [number, normalKeys, number];
@@ -90,7 +90,7 @@ const actions: {
return x;
})
),
- [Methods.moveField]: (data, from, findex, to, tindex) => {
+ [Methods.moveField]: (data, from, findex, to, tindex, limit) => {
const oriField = data.encodings[from][findex];
const field =
to === 'dimensions'
@@ -101,14 +101,14 @@ const actions: {
return mutPath(data, 'encodings', (e) => ({
...e,
[from]: remove(data.encodings[from], findex),
- [to]: insert(data.encodings[to], field, tindex),
+ [to]: insert(data.encodings[to], field, tindex).slice(0, limit ?? Infinity),
}));
},
- [Methods.cloneField]: (data, from, findex, to, tindex, newVarKey) => {
+ [Methods.cloneField]: (data, from, findex, to, tindex, newVarKey, limit) => {
const field = { ...data.encodings[from][findex], dragId: newVarKey };
return mutPath(data, 'encodings', (e) => ({
...e,
- [to]: insert(data.encodings[to], field, tindex),
+ [to]: insert(data.encodings[to], field, tindex).slice(0, limit ?? Infinity),
}));
},
[Methods.createBinlogField]: (data, encoding, index, op, newVarKey, num) => {
diff --git a/packages/graphic-walker/src/renderer/hooks.ts b/packages/graphic-walker/src/renderer/hooks.ts
index 855abe44..0e22c071 100644
--- a/packages/graphic-walker/src/renderer/hooks.ts
+++ b/packages/graphic-walker/src/renderer/hooks.ts
@@ -33,7 +33,7 @@ export const useRenderer = (props: UseRendererProps): UseRendererResult => {
const workflow = useMemo(() => {
return toWorkflow(filters, allFields, viewDimensions, viewMeasures, defaultAggregated, sort, folds, limit > 0 ? limit : undefined);
- }, [filters, allFields, viewDimensions, viewMeasures, defaultAggregated, sort, limit]);
+ }, [filters, allFields, viewDimensions, viewMeasures, defaultAggregated, sort, folds, limit]);
const [viewData, setViewData] = useState<IRow[]>([]);
const [parsedWorkflow, setParsedWorkflow] = useState<IDataQueryWorkflowStep[]>([]);
diff --git a/packages/graphic-walker/src/renderer/index.tsx b/packages/graphic-walker/src/renderer/index.tsx
index 634b2824..2c766a25 100644
--- a/packages/graphic-walker/src/renderer/index.tsx
+++ b/packages/graphic-walker/src/renderer/index.tsx
@@ -69,27 +69,27 @@ const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, r
if (csvRef) {
csvRef.current = {
download() {
- const headers = viewDimensions.concat(viewMeasures).map(x => {
+ const headers = viewDimensions.concat(viewMeasures).map((x) => {
if (x.fid === COUNT_FIELD_ID) {
return {
name: 'Count',
- fid: COUNT_FIELD_ID
- }
+ fid: COUNT_FIELD_ID,
+ };
}
if (viewConfig.defaultAggregated && x.analyticType === 'measure') {
return {
- fid: getMeaAggKey(x.fid,x.aggName),
- name: `${x.aggName}(${x.name})`
- }
+ fid: getMeaAggKey(x.fid, x.aggName),
+ name: `${x.aggName}(${x.name})`,
+ };
}
- return {fid: x.fid, name: x.name};
+ return { fid: x.fid, name: x.name };
});
- const result = `${headers.map(x=>x.name).join(',')}\n${data.map(x => headers.map(f => x[f.fid]).join(',')).join('\n')}`;
+ const result = `${headers.map((x) => x.name).join(',')}\n${data.map((x) => headers.map((f) => x[f.fid]).join(',')).join('\n')}`;
download(result, `${chart.name}.csv`, 'text/plain');
},
- }
+ };
}
- }, [data,viewDimensions,viewMeasures,visualConfig.defaultAggregated]);
+ }, [chart.name, csvRef, data, viewDimensions, viewMeasures, viewConfig.defaultAggregated]);
// Dependencies that should not trigger effect individually
const latestFromRef = useRef({
@@ -119,19 +119,22 @@ const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, r
onChange: (idx) => vizStore.selectVisualization(idx),
});
- const handleGeomClick = useCallback((values: any, e: any) => {
- e.stopPropagation();
- runInAction(() => {
- vizStore.showEmbededMenu([e.pageX, e.pageY]);
- vizStore.setFilters(values);
- });
- const selectedMarkObject = values.vlPoint.or[0];
- vizStore.updateSelectedMarkObject(selectedMarkObject);
- }, []);
+ const handleGeomClick = useCallback(
+ (values: any, e: any) => {
+ e.stopPropagation();
+ runInAction(() => {
+ vizStore.showEmbededMenu([e.pageX, e.pageY]);
+ vizStore.setFilters(values);
+ });
+ const selectedMarkObject = values.vlPoint.or[0];
+ vizStore.updateSelectedMarkObject(selectedMarkObject);
+ },
+ [vizStore]
+ );
const handleChartResize = useCallback(
(width: number, height: number) => {
- vizStore.setVisualLayout('size',{
+ vizStore.setVisualLayout('size', {
mode: 'fixed',
width,
height,
diff --git a/packages/graphic-walker/src/renderer/specRenderer.tsx b/packages/graphic-walker/src/renderer/specRenderer.tsx
index 3af881eb..30910dad 100644
--- a/packages/graphic-walker/src/renderer/specRenderer.tsx
+++ b/packages/graphic-walker/src/renderer/specRenderer.tsx
@@ -138,7 +138,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
}
return config;
- }, [themeConfig, zeroScale, resolve, background, format.normalizedNumberFormat, format.numberFormat, format.timeFormat]);
+ }, [themeConfig, mediaTheme, zeroScale, resolve, background, format.normalizedNumberFormat, format.numberFormat, format.timeFormat]);
if (isPivotTable) {
return (
@@ -177,14 +177,10 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
topLeft: false,
}
}
- size={
- size.mode === 'fixed' || isSpatial
- ? {
+ size={{
width: size.width + 'px',
height: size.height + 'px',
- }
- : undefined
- }
+ }}
>
{loading && <LoadingLayer />}
{isSpatial && (
diff --git a/packages/graphic-walker/src/segments/segmentNav.tsx b/packages/graphic-walker/src/segments/segmentNav.tsx
index 6a0b201f..9ef161e4 100644
--- a/packages/graphic-walker/src/segments/segmentNav.tsx
+++ b/packages/graphic-walker/src/segments/segmentNav.tsx
@@ -28,7 +28,7 @@ const SegmentNav: React.FC = (props) => {
const editLabelHandler = useCallback((content: string, tabIndex: number) => {
vizStore.setVisName(tabIndex, content)
- }, [])
+ }, [vizStore])
return (
<DefaultTab
diff --git a/packages/graphic-walker/src/segments/visNav.tsx b/packages/graphic-walker/src/segments/visNav.tsx
index c8f19a87..4aa1c872 100644
--- a/packages/graphic-walker/src/segments/visNav.tsx
+++ b/packages/graphic-walker/src/segments/visNav.tsx
@@ -26,7 +26,7 @@ const VisNav: React.FC = (props) => {
const visSelectionHandler = useCallback((tabKey: string, tabIndex: number) => {
if (tabKey === ADD_KEY) {
- vizStore.addVisualization(t('main.tablist.auto_title', { idx: visLength + 1 }));
+ vizStore.addVisualization(idx => t('main.tablist.auto_title', { idx }));
} else {
vizStore.selectVisualization(tabIndex);
}
@@ -34,15 +34,15 @@ const VisNav: React.FC = (props) => {
const editLabelHandler = useCallback((content: string, tabIndex: number) => {
vizStore.setVisName(tabIndex, content)
- }, [])
+ }, [vizStore])
const deleteHandler = useCallback((tabIndex: number) => {
vizStore.openRemoveConfirmModal(tabIndex);
- }, [])
+ }, [vizStore])
const dupHandler = useCallback((tabIndex: number) => {
vizStore.duplicateVisualization(tabIndex);
- }, [])
+ }, [vizStore])
return (
<EditableTabs
diff --git a/packages/graphic-walker/src/store/dataStore.ts b/packages/graphic-walker/src/store/dataStore.ts
index 228baaab..103db49d 100644
--- a/packages/graphic-walker/src/store/dataStore.ts
+++ b/packages/graphic-walker/src/store/dataStore.ts
@@ -1,5 +1,5 @@
import { computed, makeAutoObservable, toJS } from 'mobx';
-import { DataSet, IAnalyticType, IDataSource, IMutField, IRow, ISemanticType } from '../interfaces';
+import { DataSet, IAnalyticType, IDataSource, IMutField, IRow, ISegmentKey, ISemanticType } from '../interfaces';
import { VizSpecStore } from './visualSpecStore';
import { getComputation } from '../computation/clientComputation';
import { IStoInfo, IStoInfoV2, IStoInfoV2SchemaUrl } from '../utils/save';
@@ -41,8 +41,9 @@ export class DataStore {
get visSpecStore() {
if (!this.metaId || !this.meta.length) return emptyVizStore;
- if (!this.visDict[this.metaId])
+ if (!this.visDict[this.metaId]) {
this.visDict[this.metaId] = new VizSpecStore(this.meta, { onMetaChange: (f, d) => this.updateCurrentDatasetMetas(f, d) });
+ }
return this.visDict[this.metaId];
}
diff --git a/packages/graphic-walker/src/store/index.tsx b/packages/graphic-walker/src/store/index.tsx
index b503a84d..b1eded52 100644
--- a/packages/graphic-walker/src/store/index.tsx
+++ b/packages/graphic-walker/src/store/index.tsx
@@ -48,7 +48,7 @@ export const StoreWrapper = (props: StoreWrapperProps) => {
};
}
return noop;
- }, [props.storeRef]);
+ }, [props.storeRef, store]);
return <StoreContext.Provider value={store}>{props.children}</StoreContext.Provider>;
};
@@ -72,7 +72,7 @@ export const VizStoreWrapper = (props: VizStoreWrapperProps) => {
store.setMeta(props.meta);
lastMeta.current = props.meta;
}
- }, [props.meta]);
+ }, [props.meta, store]);
useEffect(() => {
if (props.storeRef) {
const ref = props.storeRef;
@@ -82,7 +82,7 @@ export const VizStoreWrapper = (props: VizStoreWrapperProps) => {
};
}
return noop;
- }, [props.storeRef]);
+ }, [props.storeRef, store]);
return <VisContext.Provider value={store}>{props.children}</VisContext.Provider>;
};
diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.ts
index 277010d0..b7f0f626 100644
--- a/packages/graphic-walker/src/store/visualSpecStore.ts
+++ b/packages/graphic-walker/src/store/visualSpecStore.ts
@@ -73,9 +73,10 @@ const viewEncodingKeys = (geom: string) => {
export class VizSpecStore {
visList: VisSpecWithHistory[];
visIndex: number = 0;
+ createdVis: number = 0;
editingFilterIdx: number | null = null;
meta: IMutField[];
- segmentKey: ISegmentKey = ISegmentKey.data;
+ segmentKey: ISegmentKey = ISegmentKey.vis;
showInsightBoard: boolean = false;
vizEmbededMenu: { show: boolean; position: [number, number] } = { show: false, position: [0, 0] };
showDataConfig: boolean = false;
@@ -103,6 +104,7 @@ export class VizSpecStore {
) {
this.meta = meta;
this.visList = options?.empty ? [] : [fromFields(meta, 'Chart 1')];
+ this.createdVis = this.visList.length;
this.onMetaChange = options?.onMetaChange;
makeAutoObservable(this, {
visList: observable.shallow,
@@ -253,13 +255,15 @@ export class VizSpecStore {
this.meta = meta;
}
- resetVisualization() {
- this.visList = [fromFields(this.meta, 'Chart 1')];
+ resetVisualization(name = 'Chart 1') {
+ this.visList = [fromFields(this.meta, name)];
+ this.createdVis = 1;
}
- addVisualization(defaultName?: string) {
- const name = defaultName || 'Chart ' + (this.visList.length + 1);
+ addVisualization(defaultName?: string | ((index: number) => string)) {
+ const name = defaultName ? (typeof defaultName === 'function' ? defaultName(this.createdVis + 1) : defaultName) : 'Chart ' + (this.createdVis + 1);
this.visList.push(fromFields(this.meta, name));
+ this.createdVis += 1;
this.visIndex = this.visList.length - 1;
}
@@ -277,6 +281,7 @@ export class VizSpecStore {
visId: uniqueId(),
})
);
+ this.createdVis += 1;
this.visIndex = this.visList.length - 1;
}
@@ -324,8 +329,9 @@ export class VizSpecStore {
}
const sourceMeta = GLOBAL_CONFIG.META_FIELD_KEYS.includes(sourceKey);
const destMeta = GLOBAL_CONFIG.META_FIELD_KEYS.includes(destinationKey);
+ const limit = GLOBAL_CONFIG.CHANNEL_LIMIT[destinationKey] ?? Infinity;
if (destMeta === sourceMeta) {
- this.visList[this.visIndex] = performers.moveField(this.visList[this.visIndex], sourceKey, sourceIndex, destinationKey, destinationIndex);
+ this.visList[this.visIndex] = performers.moveField(this.visList[this.visIndex], sourceKey, sourceIndex, destinationKey, destinationIndex, limit);
} else if (destMeta) {
this.visList[this.visIndex] = performers.removeField(this.visList[this.visIndex], sourceKey, sourceIndex);
} else {
@@ -335,7 +341,8 @@ export class VizSpecStore {
sourceIndex,
destinationKey,
destinationIndex,
- uniqueId()
+ uniqueId(),
+ limit,
);
}
}
@@ -427,23 +434,27 @@ export class VizSpecStore {
return fromSnapshot(convertChart(visSpecDecoder(forwardVisualConfigs(x))));
}
});
+ this.createdVis = this.visList.length;
this.visIndex = 0;
}
appendRaw(data: string) {
const newChart = importFull(data);
this.visList.push(newChart);
+ this.createdVis += 1;
this.visIndex = this.visList.length - 1;
}
importRaw(data: string[]) {
this.visList = data.map(importFull);
+ this.createdVis = this.visList.length;
this.visIndex = 0;
}
appendFromOld(data: IVisSpecForExport) {
const newChart = fromSnapshot(convertChart(visSpecDecoder(forwardVisualConfigs(data))));
this.visList.push(newChart);
+ this.createdVis += 1;
this.visIndex = this.visList.length - 1;
}
diff --git a/packages/graphic-walker/src/vanilla.tsx b/packages/graphic-walker/src/vanilla.tsx
index 1b1ce985..14624a8d 100644
--- a/packages/graphic-walker/src/vanilla.tsx
+++ b/packages/graphic-walker/src/vanilla.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
-import { GraphicWalker } from './index';
+import { FullGraphicWalker, GraphicWalker } from './index';
import { IGWProps } from './FullApp';
@@ -20,11 +20,11 @@ export function embedGraphicWalker(dom: HTMLElement | null, props: IGWProps | un
}
// @ts-ignore
const root = ReactDOM.createRoot(dom as HTMLElement);
- root.render(<GraphicWalker themeKey="g2" {...props} />);
+ root.render(<FullGraphicWalker themeKey="g2" {...props} />);
} else {
ReactDOM.render(
<React.StrictMode>
- <GraphicWalker themeKey="g2" {...props} />
+ <FullGraphicWalker themeKey="g2" {...props} />
</React.StrictMode>,
dom as HTMLElement
);
diff --git a/packages/graphic-walker/src/vis/react-vega.tsx b/packages/graphic-walker/src/vis/react-vega.tsx
index 414605c7..9cfd6b66 100644
--- a/packages/graphic-walker/src/vis/react-vega.tsx
+++ b/packages/graphic-walker/src/vis/react-vega.tsx
@@ -118,19 +118,23 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
} = props;
const [viewPlaceholders, setViewPlaceholders] = useState<React.MutableRefObject<HTMLDivElement>[]>([]);
const mediaTheme = useCurrentMediaTheme(dark);
- const channelScales = channelScaleRaw ?? {};
- if (scale?.opacity) {
- channelScales.opacity = {
- ...channelScales.opacity ?? {},
- ...scale.opacity
- };
- }
- if (scale?.size) {
- channelScales.size = {
- ...channelScales.size ?? {},
- ...scale.size
- };
- }
+ const channelScales = useMemo(() => {
+ const cs = channelScaleRaw ?? {};
+ if (scale?.opacity) {
+ cs.opacity = {
+ ...(cs.opacity ?? {}),
+ ...scale.opacity,
+ };
+ }
+ if (scale?.size) {
+ cs.size = {
+ ...(cs.size ?? {}),
+ ...scale.size,
+ };
+ }
+ return cs;
+}, [channelScaleRaw, scale]);
+
// const themeConfig = builtInThemes[themeKey]?.[mediaTheme];
// const vegaConfig = useMemo(() => {
@@ -166,7 +170,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
const rowFacetFields = useMemo(() => rowDims.slice(0, -1), [rowDims]);
const colFacetFields = useMemo(() => colDims.slice(0, -1), [colDims]);
const rowRepeatFields = useMemo(() => rowMeas.length === 0 ? rowDims.slice(-1) : rowMeas, [rowDims, rowMeas]);//rowMeas.slice(0, -1);
- const colRepeatFields = useMemo(() => colMeas.length === 0 ? colDims.slice(-1) : colMeas, [rowDims, rowMeas]);//colMeas.slice(0, -1);
+ const colRepeatFields = useMemo(() => colMeas.length === 0 ? colDims.slice(-1) : colMeas, [colDims, colMeas]);//colMeas.slice(0, -1);
const allFieldIds = useMemo(() => [...rows, ...columns, color, opacity, size].filter(f => Boolean(f)).map(f => (f as IViewField).fid), [rows, columns, color, opacity, size]);
const { reportError: reportGWError } = useReporter();
diff --git a/packages/graphic-walker/src/vis/theme.ts b/packages/graphic-walker/src/vis/theme.ts
index 4add30f3..af8b4a1a 100644
--- a/packages/graphic-walker/src/vis/theme.ts
+++ b/packages/graphic-walker/src/vis/theme.ts
@@ -2,7 +2,7 @@ import { VegaGlobalConfig } from '../interfaces';
export type GWGlobalConfig<
T extends VegaGlobalConfig = VegaGlobalConfig & {
- scale: {
+ scale?: {
continuous: {
range: string[];
};
diff --git a/yarn.lock b/yarn.lock
index 3e83f959..20d4207d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -795,6 +795,51 @@
resolved "https://registry.npmmirror.com/@esbuild/win32-x64/-/win32-x64-0.17.19.tgz#8cfaf2ff603e9aabb910e9c0558c26cf32744061"
integrity sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==
+"@floating-ui/core@^1.0.0", "@floating-ui/core@^1.4.2":
+ version "1.5.0"
+ resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.5.0.tgz#5c05c60d5ae2d05101c3021c1a2a350ddc027f8c"
+ integrity sha512-kK1h4m36DQ0UHGj5Ah4db7R0rHemTqqO0QLvUqi1/mUUp3LuAWbWxdxSIf/XsnH9VS6rRVPLJCncjRzUvyCLXg==
+ dependencies:
+ "@floating-ui/utils" "^0.1.3"
+
+"@floating-ui/dom@^1.0.0", "@floating-ui/dom@^1.2.1":
+ version "1.5.3"
+ resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.5.3.tgz#54e50efcb432c06c23cd33de2b575102005436fa"
+ integrity sha512-ClAbQnEqJAKCJOEbbLo5IUlZHkNszqhuxS4fHAVxRPXPya6Ysf2G8KypnYcOTpx6I8xcgF9bbHb6g/2KpbV8qA==
+ dependencies:
+ "@floating-ui/core" "^1.4.2"
+ "@floating-ui/utils" "^0.1.3"
+
+"@floating-ui/react-dom@^1.3.0":
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/@floating-ui/react-dom/-/react-dom-1.3.0.tgz#4d35d416eb19811c2b0e9271100a6aa18c1579b3"
+ integrity sha512-htwHm67Ji5E/pROEAr7f8IKFShuiCKHwUC/UY4vC3I5jiSvGFAYnSYiZO5MlGmads+QqvUkR9ANHEguGrDv72g==
+ dependencies:
+ "@floating-ui/dom" "^1.2.1"
+
+"@floating-ui/react@^0.19.0":
+ version "0.19.2"
+ resolved "https://registry.yarnpkg.com/@floating-ui/react/-/react-0.19.2.tgz#c6e4d2097ed0dca665a7c042ddf9cdecc95e9412"
+ integrity sha512-JyNk4A0Ezirq8FlXECvRtQOX/iBe5Ize0W/pLkrZjfHW9GUV7Xnq6zm6fyZuQzaHHqEnVizmvlA96e1/CkZv+w==
+ dependencies:
+ "@floating-ui/react-dom" "^1.3.0"
+ aria-hidden "^1.1.3"
+ tabbable "^6.0.1"
+
+"@floating-ui/utils@^0.1.3":
+ version "0.1.6"
+ resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.1.6.tgz#22958c042e10b67463997bd6ea7115fe28cbcaf9"
+ integrity sha512-OfX7E2oUDYxtBvsuS4e/jSn4Q9Qb6DzgeYtsAdkPZ47znpoNsMgZw0+tVijiv3uGNR6dgNlty6r9rzIzHjtd/A==
+
+"@headlessui-float/react@^0.11.4":
+ version "0.11.4"
+ resolved "https://registry.yarnpkg.com/@headlessui-float/react/-/react-0.11.4.tgz#56bdf96dc8c206ae7adda8b1960f354f32876320"
+ integrity sha512-4I72p196YZuASAnXQSgiS7Rrby2rjPOe0b55mWo0Kq3RS2CPBmSK5yLlN3vfiF2XKqY5Ko3/AFStLirnrXSkTw==
+ dependencies:
+ "@floating-ui/core" "^1.0.0"
+ "@floating-ui/dom" "^1.0.0"
+ "@floating-ui/react" "^0.19.0"
+
"@headlessui/react@^1.7.12":
version "1.7.12"
resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-1.7.12.tgz#9ab2baa3c4f632782631e00937f9531a34033619"
@@ -1616,6 +1661,13 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"
+aria-hidden@^1.1.3:
+ version "1.2.3"
+ resolved "https://registry.yarnpkg.com/aria-hidden/-/aria-hidden-1.2.3.tgz#14aeb7fb692bbb72d69bebfa47279c1fd725e954"
+ integrity sha512-xcLxITLe2HYa1cnYnwCjkOO1PqUHQpozB8x9AR0OgWN2woOBi5kSDVxKfd0b7sb1hw5qFeJhXm9H1nu3xSfLeQ==
+ dependencies:
+ tslib "^2.0.0"
+
attr-accept@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/attr-accept/-/attr-accept-2.2.2.tgz#646613809660110749e92f2c10833b70968d929b"
@@ -4206,6 +4258,11 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
+tabbable@^6.0.1:
+ version "6.2.0"
+ resolved "https://registry.yarnpkg.com/tabbable/-/tabbable-6.2.0.tgz#732fb62bc0175cfcec257330be187dcfba1f3b97"
+ integrity sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==
+
tailwindcss@^3.2.4:
version "3.2.7"
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.2.7.tgz#5936dd08c250b05180f0944500c01dce19188c07"
@@ -4312,16 +4369,16 @@ ts-jest@^29.1.1:
semver "^7.5.3"
yargs-parser "^21.0.1"
+tslib@^2.0.0, tslib@^2.4.0:
+ version "2.6.2"
+ resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
+ integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
+
tslib@^2.1.0, tslib@^2.5.0, tslib@~2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==
-tslib@^2.4.0:
- version "2.6.2"
- resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
- integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
-
version "4.0.8"
resolved "https://registry.npmmirror.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"