Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: drag issues and tab issues (#352)

islxyqwed873c43b166c
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsx
index ce643087..551a649c 100644
--- a/packages/graphic-walker/src/App.tsx
+++ b/packages/graphic-walker/src/App.tsx
@@ -229,8 +229,7 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
<PosFields />
</div>
<div
- className="my-0.5 sm:ml-0.5 p-1 border relative"
- style={{ minHeight: '600px', height: 1, maxHeight: '100vh', overflow: 'auto' }}
+ className="my-0.5 sm:ml-0.5 p-1 border relative h-[600px]"
onMouseLeave={() => {
vizEmbededMenu.show && vizStore.closeEmbededMenu();
}}
diff --git a/packages/graphic-walker/src/components/actionMenu/index.tsx b/packages/graphic-walker/src/components/actionMenu/index.tsx
index d34d2a88..9e0c1988 100644
--- a/packages/graphic-walker/src/components/actionMenu/index.tsx
+++ b/packages/graphic-walker/src/components/actionMenu/index.tsx
@@ -40,9 +40,7 @@ const ActionMenu: React.FC<IActionMenuProps & Omit<HTMLAttributes<HTMLDivElement
const [coord, setCoord] = useState<[x: number, y: number]>([0, 0]);
const buttonRef = useRef<HTMLButtonElement>(null);
- if (disabled || menu.length === 0) {
- return <div {...attrs}>{props.children}</div>;
- }
+ const isDisabled = disabled || menu.length === 0;
const block = useContext(blockContext);
@@ -71,6 +69,7 @@ const ActionMenu: React.FC<IActionMenuProps & Omit<HTMLAttributes<HTMLDivElement
<Menu.Button ref={buttonRef} className="sr-only" aria-hidden />
<div
onContextMenu={(e) => {
+ if (isDisabled) return;
e.preventDefault();
e.stopPropagation();
const blockRect = block.current?.getBoundingClientRect();
@@ -85,7 +84,7 @@ const ActionMenu: React.FC<IActionMenuProps & Omit<HTMLAttributes<HTMLDivElement
{props.children}
</div>
{open && <div className="fixed inset-0 z-50 bg-transparent" aria-hidden="true" />}
- <Transition
+ {!isDisabled && <Transition
as={Fragment}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
@@ -103,7 +102,7 @@ const ActionMenu: React.FC<IActionMenuProps & Omit<HTMLAttributes<HTMLDivElement
>
<ActionMenuItemList title={title} items={menu} onDismiss={close} />
</Menu.Items>
- </Transition>
+ </Transition>}
</Context.Provider>
);
}}
diff --git a/packages/graphic-walker/src/components/chat/index.tsx b/packages/graphic-walker/src/components/chat/index.tsx
index 5eea2f35..4d89c0b1 100644
--- a/packages/graphic-walker/src/components/chat/index.tsx
+++ b/packages/graphic-walker/src/components/chat/index.tsx
@@ -13,6 +13,7 @@ import { getSort, parseErrorMessage } from '@/utils';
import { useReporter } from '@/utils/reportError';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible';
import { Textarea } from '../ui/textarea';
+import LoadingLayer from '../loadingLayer';
async function fetchQueryChat(api: string, metas: IViewField[], messages: IChatMessage[], headers: Record<string, string>) {
const res = await fetch(api, {
@@ -143,10 +144,10 @@ const AssistantMessage = observer(function AssistantMessage(props: { message: IA
)}
</div>
<CardContent className="pl-16">
+ {waiting && <LoadingLayer />}
<SpecRenderer
themeConfig={themeConfig}
name={name}
- loading={waiting}
data={data}
themeKey={themeKey}
draggableFieldState={encodings}
diff --git a/packages/graphic-walker/src/components/painter/index.tsx b/packages/graphic-walker/src/components/painter/index.tsx
index 34305a05..2e3d659e 100644
--- a/packages/graphic-walker/src/components/painter/index.tsx
+++ b/packages/graphic-walker/src/components/painter/index.tsx
@@ -299,7 +299,7 @@ const PainterContent = (props: {
};
if (e instanceof MouseEvent && e.buttons & MouseButtons.PRIMARY) {
paint(e.offsetX - origin[0] - MAGIC_PADDING, e.offsetY - origin[1] - MAGIC_PADDING);
- } else if (e instanceof TouchEvent) {
+ } else if (window.TouchEvent && e instanceof TouchEvent) {
const rect = containerRef.current!.getBoundingClientRect();
paint(
e.changedTouches[0].pageX - rect.left - origin[0] - MAGIC_PADDING,
diff --git a/packages/graphic-walker/src/components/pivotTable/index.tsx b/packages/graphic-walker/src/components/pivotTable/index.tsx
index 26584074..a5b5220b 100644
--- a/packages/graphic-walker/src/components/pivotTable/index.tsx
+++ b/packages/graphic-walker/src/components/pivotTable/index.tsx
@@ -18,7 +18,6 @@ import { getSort, getSortedEncoding } from '../../utils';
interface PivotTableProps {
themeKey?: IThemeKey;
data: IRow[];
- loading: boolean;
draggableFieldState: DeepReadonly<DraggableFieldState>;
visualConfig: IVisualConfigNew;
layout: IVisualLayout;
@@ -27,7 +26,7 @@ interface PivotTableProps {
const emptyMap = new Map();
const PivotTable: React.FC<PivotTableProps> = observer(function PivotTableComponent(props) {
- const { data, visualConfig, loading, layout, draggableFieldState } = props;
+ const { data, visualConfig, layout, draggableFieldState } = props;
const computation = useCompututaion();
const appRef = useAppRootContext();
const [leftTree, setLeftTree] = useState<INestNode | null>(null);
@@ -191,7 +190,7 @@ const PivotTable: React.FC<PivotTableProps> = observer(function PivotTableCompon
// const { leftTree, topTree, metricTable } = store;
return (
<div className="relative">
- {(isLoading || loading) && <LoadingLayer />}
+ {isLoading && <LoadingLayer />}
<div className="flex">
<table className="border border-collapse">
<thead className="border">
diff --git a/packages/graphic-walker/src/components/toolbar/index.tsx b/packages/graphic-walker/src/components/toolbar/index.tsx
index 3a175fb5..c99508a4 100644
--- a/packages/graphic-walker/src/components/toolbar/index.tsx
+++ b/packages/graphic-walker/src/components/toolbar/index.tsx
@@ -15,7 +15,7 @@ const Toolbar = memo<ToolbarProps>(function Toolbar({ items }) {
const [openedKey, setOpenedKey] = useState<string | null>(null);
return (
- <div className="flex border my-1 w-full rounded overflow-hidden">
+ <div className="flex flex-wrap sm:flex-nowrap border my-1 w-full rounded overflow-hidden">
{items.map((item, i) => {
if (item === ToolbarItemSplitter) {
return <Separator orientation="vertical" className="mx-1 my-1.5 h-6" key={i} />;
diff --git a/packages/graphic-walker/src/components/ui/tabs.tsx b/packages/graphic-walker/src/components/ui/tabs.tsx
index 14afdaf4..5322baf7 100644
--- a/packages/graphic-walker/src/components/ui/tabs.tsx
+++ b/packages/graphic-walker/src/components/ui/tabs.tsx
@@ -3,7 +3,9 @@ import * as TabsPrimitive from '@radix-ui/react-tabs';
import { cn } from '@/utils';
-const Tabs = TabsPrimitive.Root;
+const Tabs = React.forwardRef<React.ElementRef<typeof TabsPrimitive.Root>, React.ComponentPropsWithoutRef<typeof TabsPrimitive.Root>>(({ ...props }, ref) => (
+ <TabsPrimitive.Root ref={ref} activationMode="manual" {...props} />
+));
const TabsList = React.forwardRef<React.ElementRef<typeof TabsPrimitive.List>, React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>>(
({ className, ...props }, ref) => (
diff --git a/packages/graphic-walker/src/dataSource/index.tsx b/packages/graphic-walker/src/dataSource/index.tsx
index 52cc67c9..6c81acf3 100644
--- a/packages/graphic-walker/src/dataSource/index.tsx
+++ b/packages/graphic-walker/src/dataSource/index.tsx
@@ -32,14 +32,14 @@ const DataSourceSegment: React.FC<DSSegmentProps> = observer((props) => {
const { showDSPanel } = commonStore;
return (
- <div className="font-sans flex items-center m-4 p-4 border rounded-md">
+ <div className="font-sans gap-2 flex flex-wrap items-center m-4 p-4 border rounded-md">
{props.onLoad && <GwFile onImport={props.onLoad} fileRef={gwFileRef} />}
{/* <label className="text-xs mr-1 whitespace-nowrap self-center h-4">
{t("DataSource.labels.cur_dataset")}
</label> */}
- <div className="mr-2">
+ <div>
<DropdownSelect
- className='text-xs !h-8'
+ className="text-xs !h-8"
options={dataSources.map((d) => ({ label: d.name, value: d.id }))}
selectedKey={selectedId}
onSelect={onSelectId}
@@ -49,7 +49,6 @@ const DataSourceSegment: React.FC<DSSegmentProps> = observer((props) => {
<Button
size="sm"
- className="mr-2"
onClick={() => {
commonStore.startDSBuildingTask();
}}
@@ -59,7 +58,6 @@ const DataSourceSegment: React.FC<DSSegmentProps> = observer((props) => {
{onSave && (
<Button
size="sm"
- className="mr-2"
variant="outline"
onClick={async () => {
const blob = await onSave();
@@ -71,7 +69,6 @@ const DataSourceSegment: React.FC<DSSegmentProps> = observer((props) => {
)}
{props.onLoad && (
<Button
- className="mr-2"
size="sm"
variant="outline"
onClick={() => {
diff --git a/packages/graphic-walker/src/fields/components.tsx b/packages/graphic-walker/src/fields/components.tsx
index 5a0aa200..a46334da 100644
--- a/packages/graphic-walker/src/fields/components.tsx
+++ b/packages/graphic-walker/src/fields/components.tsx
@@ -54,6 +54,7 @@ export const FieldsContainer = styled.div`
> div {
margin: 1px;
}
+ touch-action: none;
`;
export const FilterFieldsContainer = styled.div({
@@ -129,6 +130,7 @@ export const Pill = styled.div<{ colType: 'discrete' | 'continuous' }>`
font-size: 12px;
height: 20px;
min-width: 150px;
+ max-width: 300px;
/* overflow-y: hidden; */
padding: 0 10px;
user-select: none;
diff --git a/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx b/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx
index 9b1a9b78..3c1c2222 100644
--- a/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx
+++ b/packages/graphic-walker/src/fields/datasetFields/dimFields.tsx
@@ -10,23 +10,19 @@ import { useMenuActions } from './utils';
import { refMapper } from '../fieldsContext';
import { getFieldIdentifier } from '@/utils';
-interface Props {
- provided: DroppableProvided;
-}
-const DimFields: React.FC<Props> = (props) => {
- const { provided } = props;
+const DimFields: React.FC = (props) => {
const vizStore = useVizStore();
const { dimensions } = vizStore;
const menuActions = useMenuActions('dimensions');
return (
- <div {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
+ <div className="touch-none">
{dimensions.map((f, index) => (
<Draggable key={getFieldIdentifier(f)} draggableId={`dimension_${getFieldIdentifier(f)}`} index={index}>
{(provided, snapshot) => {
return (
- <ActionMenu title={f.name || f.fid} menu={menuActions[index]} enableContextMenu disabled={snapshot.isDragging}>
+ <ActionMenu title={f.name || f.fid} menu={menuActions[index]} enableContextMenu={false} disabled={snapshot.isDragging}>
<FieldPill
- className={`flex pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-dimension/20 transition-colors rounded-md truncate border border-transparent ${
+ className={`touch-none flex pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-dimension/20 transition-colors rounded-md truncate border border-transparent ${
snapshot.isDragging ? 'bg-dimension/20' : ''
}`}
ref={refMapper(provided.innerRef)}
diff --git a/packages/graphic-walker/src/fields/datasetFields/index.tsx b/packages/graphic-walker/src/fields/datasetFields/index.tsx
index ece0208a..da306d4c 100644
--- a/packages/graphic-walker/src/fields/datasetFields/index.tsx
+++ b/packages/graphic-walker/src/fields/datasetFields/index.tsx
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import DimFields from './dimFields';
import MeaFields from './meaFields';
+import { refMapper } from '../fieldsContext';
const DSContainer = styled.div`
@media (min-width: 640px) {
@@ -17,16 +18,24 @@ const DatasetFields: React.FC = (props) => {
return (
<DSContainer className="p-1 sm:mr-0.5 my-0.5 border flex sm:flex-col" style={{ paddingBlock: 0, paddingInline: '0.6em' }}>
<h4 className="text-xs mb-2 flex-grow-0 cursor-default select-none mt-2">{t('field_list')}</h4>
- <div className="pd-1 overflow-y-auto" style={{ maxHeight: '380px', minHeight: '100px' }}>
- <Droppable droppableId="dimensions" direction="vertical">
- {(provided, snapshot) => <DimFields provided={provided} />}
- </Droppable>
- </div>
- <div className="border-t flex-grow pd-1 overflow-y-auto">
- <Droppable droppableId="measures" direction="vertical">
- {(provided, snapshot) => <MeaFields provided={provided} />}
- </Droppable>
- </div>
+ <Droppable droppableId="dimensions" direction="vertical">
+ {(provided, snapshot) => (
+ <div className="flex-1 min-w-[0px]" {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
+ <div className="pd-1 overflow-y-auto" style={{ maxHeight: '380px', minHeight: '100px' }}>
+ <DimFields />
+ </div>
+ </div>
+ )}
+ </Droppable>
+ <Droppable droppableId="measures" direction="vertical">
+ {(provided, snapshot) => (
+ <div className="flex-1 min-w-[0px]" {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
+ <div className="border-t flex-grow pd-1 overflow-y-auto">
+ <MeaFields />
+ </div>
+ </div>
+ )}
+ </Droppable>
</DSContainer>
);
};
diff --git a/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx b/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx
index 3e6a35c6..2b2160b7 100644
--- a/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx
+++ b/packages/graphic-walker/src/fields/datasetFields/meaFields.tsx
@@ -11,20 +11,16 @@ import { MEA_KEY_ID } from '../../constants';
import { refMapper } from '../fieldsContext';
import { getFieldIdentifier } from '@/utils';
-interface Props {
- provided: DroppableProvided;
-}
-const MeaFields: React.FC<Props> = (props) => {
- const { provided } = props;
+const MeaFields: React.FC = (props) => {
const vizStore = useVizStore();
const { measures } = vizStore;
const menuActions = useMenuActions('measures');
return (
- <div {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
+ <div className='touch-none'>
{measures.map((f, index) => (
- <Draggable key={getFieldIdentifier(f)} draggableId={`measure_${getFieldIdentifier(f)}`} index={index}>
+ <Draggable key={getFieldIdentifier(f)} draggableId={`measure_${getFieldIdentifier(f)}`} index={index}>
{(provided, snapshot) => {
return (
<div className="block">
@@ -35,7 +31,7 @@ const MeaFields: React.FC<Props> = (props) => {
disabled={snapshot.isDragging || f.fid === MEA_KEY_ID}
>
<FieldPill
- className={`flex pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-measure/20 rounded-md truncate border border-transparent ${
+ className={`touch-none flex pt-0.5 pb-0.5 pl-2 pr-2 mx-0 m-1 text-xs hover:bg-measure/20 rounded-md truncate border border-transparent ${
snapshot.isDragging ? 'bg-measure/20' : ''
}`}
isDragging={snapshot.isDragging}
diff --git a/packages/graphic-walker/src/fields/encodeFields/multiEncodeEditor.tsx b/packages/graphic-walker/src/fields/encodeFields/multiEncodeEditor.tsx
index c508ac40..99475ea6 100644
--- a/packages/graphic-walker/src/fields/encodeFields/multiEncodeEditor.tsx
+++ b/packages/graphic-walker/src/fields/encodeFields/multiEncodeEditor.tsx
@@ -29,9 +29,9 @@ interface MultiEncodeEditorProps {
const SingleEncodeEditor: React.FC<MultiEncodeEditorProps> = (props) => {
const { dkey, provided, snapshot } = props;
const vizStore = useVizStore();
- const { allEncodings, config, allFields } = vizStore;
+ const { currentEncodings, config, allFields } = vizStore;
const folds = config.folds ?? [];
- const channelItems = allEncodings[dkey.id];
+ const channelItems = currentEncodings[dkey.id];
const { t } = useTranslation();
const aggregationOptions = useMemo(() => {
@@ -50,7 +50,7 @@ const SingleEncodeEditor: React.FC<MultiEncodeEditorProps> = (props) => {
}, [allFields]);
return (
- <div className="relative select-none flex flex-col py-0.5 px-1" {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
+ <div className="relative select-none flex flex-col py-0.5 px-1 touch-none" {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
{channelItems.map((channelItem, index) => {
return (
<Draggable key={getFieldIdentifier(channelItem)} draggableId={`encode_${dkey.id}_${getFieldIdentifier(channelItem)}`} index={index}>
@@ -61,7 +61,7 @@ const SingleEncodeEditor: React.FC<MultiEncodeEditorProps> = (props) => {
{...provided.draggableProps}
{...provided.dragHandleProps}
className={
- 'flex items-stretch h-[30px] my-0.5 relative' +
+ 'flex items-stretch h-[30px] my-0.5 relative touch-none' +
(provided.draggableProps.style?.transform ? ' z-10' : '') +
(channelItem.aggName === 'expr' && !config.defaultAggregated ? ' !opacity-50' : '')
}
diff --git a/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx b/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx
index 07d18cdf..a807fa77 100644
--- a/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx
+++ b/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx
@@ -50,7 +50,7 @@ const SingleEncodeEditor: React.FC<SingleEncodeEditorProps> = (props) => {
}, [allFields]);
return (
- <div className="p-1 select-none relative" {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
+ <div className="p-1 select-none relative touch-none" {...provided.droppableProps} ref={refMapper(provided.innerRef)}>
<div
className={`p-1.5 bg-muted text-muted-foreground border flex item-center justify-center grow ${
snapshot.draggingFromThisWith || snapshot.isDraggingOver || !channelItem ? 'opacity-100' : 'opacity-0'
@@ -67,7 +67,7 @@ const SingleEncodeEditor: React.FC<SingleEncodeEditorProps> = (props) => {
{...provided.draggableProps}
{...provided.dragHandleProps}
className={
- 'flex items-stretch absolute top-0 left-0 right-0 bottom-0 m-1' +
+ 'flex items-stretch absolute top-0 left-0 right-0 bottom-0 m-1 touch-none' +
(provided.draggableProps.style?.transform ? ' z-10' : '') +
(channelItem.aggName === 'expr' && !config.defaultAggregated ? ' !opacity-50' : '')
}
diff --git a/packages/graphic-walker/src/fields/filterField/filterPill.tsx b/packages/graphic-walker/src/fields/filterField/filterPill.tsx
index 9f866e86..a53bcc2c 100644
--- a/packages/graphic-walker/src/fields/filterField/filterPill.tsx
+++ b/packages/graphic-walker/src/fields/filterField/filterPill.tsx
@@ -71,7 +71,7 @@ const FilterPill: React.FC<FilterPillProps> = observer((props) => {
const fieldName = field.enableAgg ? `${field.aggName}(${field.name})` : field.name;
return (
- <Pill className="text-foreground" ref={refMapper(provided.innerRef)} {...provided.draggableProps} {...provided.dragHandleProps}>
+ <Pill className="text-foreground touch-none" ref={refMapper(provided.innerRef)} {...provided.draggableProps} {...provided.dragHandleProps}>
<header className="bg-secondary">{fieldName}</header>
<div
className="bg-background text-muted-foreground hover:bg-accent flex flex-row output"
diff --git a/packages/graphic-walker/src/fields/filterField/index.tsx b/packages/graphic-walker/src/fields/filterField/index.tsx
index a6f5b851..b9cdfb13 100644
--- a/packages/graphic-walker/src/fields/filterField/index.tsx
+++ b/packages/graphic-walker/src/fields/filterField/index.tsx
@@ -23,6 +23,7 @@ const FilterItemContainer: React.FC<FieldContainerProps> = observer(({ provided
return (
<FilterFieldsContainer
+ className='touch-none'
{...provided.droppableProps}
ref={refMapper(provided.innerRef)}
>
diff --git a/packages/graphic-walker/src/fields/obComponents/obPill.tsx b/packages/graphic-walker/src/fields/obComponents/obPill.tsx
index 4f40e144..c0c35cac 100644
--- a/packages/graphic-walker/src/fields/obComponents/obPill.tsx
+++ b/packages/graphic-walker/src/fields/obComponents/obPill.tsx
@@ -45,7 +45,7 @@ const OBPill: React.FC<PillProps> = (props) => {
<Pill
ref={refMapper(provided.innerRef)}
colType={field.analyticType === 'dimension' ? 'discrete' : 'continuous'}
- className={`${field.aggName === 'expr' && !config.defaultAggregated ? '!opacity-50' : ''}`}
+ className={`${field.aggName === 'expr' && !config.defaultAggregated ? '!opacity-50 touch-none' : 'touch-none'}`}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
diff --git a/packages/graphic-walker/src/renderer/index.tsx b/packages/graphic-walker/src/renderer/index.tsx
index 9fb36f06..aa73a4ec 100644
--- a/packages/graphic-walker/src/renderer/index.tsx
+++ b/packages/graphic-walker/src/renderer/index.tsx
@@ -1,6 +1,16 @@
import { observer } from 'mobx-react-lite';
import React, { useState, useEffect, forwardRef, useRef, useCallback, useMemo } from 'react';
-import { DraggableFieldState, IDarkMode, IRow, IThemeKey, IComputationFunction, IVisualConfigNew, IChannelScales, IViewField, IVisualLayout } from '../interfaces';
+import {
+ DraggableFieldState,
+ IDarkMode,
+ IRow,
+ IThemeKey,
+ IComputationFunction,
+ IVisualConfigNew,
+ IChannelScales,
+ IViewField,
+ IVisualLayout,
+} from '../interfaces';
import { useTranslation } from 'react-i18next';
import SpecRenderer from './specRenderer';
import { runInAction } from 'mobx';
@@ -18,6 +28,7 @@ import { GWGlobalConfig } from '../vis/theme';
import { GLOBAL_CONFIG } from '../config';
import { Item } from 'vega';
import { viewEncodingKeys } from '@/models/visSpec';
+import LoadingLayer from '@/components/loadingLayer';
interface RendererProps {
themeKey?: IThemeKey;
@@ -57,7 +68,6 @@ const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, r
[layout, overrideSize]
);
-
const draggableFieldState = chart.encodings;
const { i18n } = useTranslation();
@@ -198,24 +208,28 @@ const Renderer = forwardRef<IReactVegaHandler, RendererProps>(function (props, r
}, [isSpatial, vizStore]);
return (
- <SpecRenderer
- name={chart?.name}
- loading={waiting}
- data={viewData}
- ref={ref}
- themeKey={themeKey}
- themeConfig={themeConfig}
- locale={i18n.language}
- draggableFieldState={encodings}
- visualConfig={viewConfig}
- onGeomClick={handleGeomClick}
- onChartResize={handleChartResize}
- layout={visualLayout}
- channelScales={props.channelScales}
- onReportSpec={(spec) => {
- vizStore.updateLastSpec(spec);
- }}
- />
+ <div className='w-full h-full'>
+ {waiting && <LoadingLayer />}
+ <div className='overflow-auto w-full h-full'>
+ <SpecRenderer
+ name={chart?.name}
+ data={viewData}
+ ref={ref}
+ themeKey={themeKey}
+ themeConfig={themeConfig}
+ locale={i18n.language}
+ draggableFieldState={encodings}
+ visualConfig={viewConfig}
+ onGeomClick={handleGeomClick}
+ onChartResize={handleChartResize}
+ layout={visualLayout}
+ channelScales={props.channelScales}
+ onReportSpec={(spec) => {
+ vizStore.updateLastSpec(spec);
+ }}
+ />
+ </div>
+ </div>
);
});
diff --git a/packages/graphic-walker/src/renderer/pureRenderer.tsx b/packages/graphic-walker/src/renderer/pureRenderer.tsx
index 7c2f273a..1e84f9e7 100644
--- a/packages/graphic-walker/src/renderer/pureRenderer.tsx
+++ b/packages/graphic-walker/src/renderer/pureRenderer.tsx
@@ -25,6 +25,7 @@ import { getSort } from '../utils';
import { GWGlobalConfig } from '../vis/theme';
import { VizAppContext } from '../store/context';
import { useCurrentMediaTheme } from '../utils/media';
+import LoadingLayer from '@/components/loadingLayer';
type IPureRendererProps = {
className?: string;
@@ -142,6 +143,7 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps & (LocalPr
vegaThemeContext={{ themeConfig, themeKey }}
portalContainerContext={portal}
>
+ {waiting && <LoadingLayer />}
<div className={`relative ${darkMode === 'dark' ? 'dark' : ''}`} style={sizeMode === 'full' ? { width: '100%', height: '100%' } : undefined}>
{isSpatial && (
<div className="max-w-full" style={{ height: LEAFLET_DEFAULT_HEIGHT, flexGrow: 1 }}>
@@ -152,7 +154,6 @@ const PureRenderer = forwardRef<IReactVegaHandler, IPureRendererProps & (LocalPr
<SpecRenderer
themeConfig={themeConfig}
name={name}
- loading={waiting}
data={viewData}
ref={ref}
themeKey={themeKey}
diff --git a/packages/graphic-walker/src/renderer/specRenderer.tsx b/packages/graphic-walker/src/renderer/specRenderer.tsx
index 83333440..55f8a014 100644
--- a/packages/graphic-walker/src/renderer/specRenderer.tsx
+++ b/packages/graphic-walker/src/renderer/specRenderer.tsx
@@ -15,7 +15,6 @@ interface SpecRendererProps {
name?: string;
themeKey?: IThemeKey;
data: IRow[];
- loading: boolean;
draggableFieldState: DraggableFieldState;
visualConfig: IVisualConfigNew;
layout: IVisualLayout;
@@ -36,7 +35,6 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
layout,
themeKey,
data,
- loading,
draggableFieldState,
visualConfig,
onGeomClick,
@@ -130,113 +128,99 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
}, [themeConfig, mediaTheme, zeroScale, resolve, background, format.normalizedNumberFormat, format.numberFormat, format.timeFormat]);
if (isPivotTable) {
- return (
- <PivotTable
- data={data}
- draggableFieldState={draggableFieldState}
- visualConfig={visualConfig}
- layout={layout}
- loading={loading}
- themeKey={themeKey}
- />
- );
+ return <PivotTable data={data} draggableFieldState={draggableFieldState} visualConfig={visualConfig} layout={layout} themeKey={themeKey} />;
}
const isSpatial = coordSystem === 'geographic';
return (
- <>
- {loading && <LoadingLayer />}
- <Resizable
- className={
- enableResize ? 'border-primary border-2 overflow-hidden inline-block max-h-screen max-w-[100vw]' : 'inline-block max-h-screen max-w-[100vw]'
- }
- style={{ padding: '12px' }}
- onResizeStop={(e, direction, ref, d) => {
- onChartResize?.(size.width + d.width, size.height + d.height);
- }}
- enable={
- enableResize
- ? undefined
- : {
- top: false,
- right: false,
- bottom: false,
- left: false,
- topRight: false,
- bottomRight: false,
- bottomLeft: false,
- topLeft: false,
- }
- }
- size={
- // ensure PureRenderer with Auto size is correct
- size.mode === 'fixed'
- ? {
- width: size.width + 'px',
- height: size.height + 'px',
- }
- : size.mode === 'full'
- ? {
- width: '100%',
- height: '100%',
- }
- : isSpatial
- ? {
- width: LEAFLET_DEFAULT_WIDTH + 'px',
- height: LEAFLET_DEFAULT_HEIGHT + 'px',
- }
- : { width: 'auto', height: 'auto' }
- }
- >
- {isSpatial && (
- <LeafletRenderer
- name={name}
- data={data}
- draggableFieldState={draggableFieldState}
- visualConfig={visualConfig}
- visualLayout={layout}
- vegaConfig={vegaConfig}
- channelScales={channelScales}
- scale={scale}
- />
- )}
- {isSpatial || (
- <ReactVega
- name={name}
- vegaConfig={vegaConfig}
- // format={format}
- layoutMode={size.mode}
- interactiveScale={interactiveScale}
- geomType={geoms[0]}
- defaultAggregate={defaultAggregated}
- stack={stack}
- dataSource={data}
- rows={rows}
- columns={columns}
- color={color[0]}
- theta={theta[0]}
- radius={radius[0]}
- shape={shape[0]}
- opacity={opacity[0]}
- size={sizeChannel[0]}
- details={details}
- text={text[0]}
- showActions={showActions}
- width={size.width - 12 * 4}
- height={size.height - 12 * 4}
- ref={ref}
- onGeomClick={onGeomClick}
- locale={locale}
- useSvg={useSvg}
- channelScales={channelScales}
- scale={scale}
- onReportSpec={onReportSpec}
- displayOffset={timezoneDisplayOffset}
- />
- )}
- </Resizable>
- </>
+ <Resizable
+ className={enableResize ? 'border-primary border-2 max-h-screen max-w-[100vw]' : 'max-h-screen max-w-[100vw]'}
+ style={{ padding: '12px' }}
+ onResizeStop={(e, direction, ref, d) => {
+ onChartResize?.(size.width + d.width, size.height + d.height);
+ }}
+ enable={
+ enableResize
+ ? undefined
+ : {
+ top: false,
+ right: false,
+ bottom: false,
+ left: false,
+ topRight: false,
+ bottomRight: false,
+ bottomLeft: false,
+ topLeft: false,
+ }
+ }
+ size={
+ // ensure PureRenderer with Auto size is correct
+ size.mode === 'fixed'
+ ? {
+ width: size.width + 'px',
+ height: size.height + 'px',
+ }
+ : size.mode === 'full'
+ ? {
+ width: '100%',
+ height: '100%',
+ }
+ : isSpatial
+ ? {
+ width: LEAFLET_DEFAULT_WIDTH + 'px',
+ height: LEAFLET_DEFAULT_HEIGHT + 'px',
+ }
+ : { width: 'auto', height: 'auto' }
+ }
+ >
+ {isSpatial && (
+ <LeafletRenderer
+ name={name}
+ data={data}
+ draggableFieldState={draggableFieldState}
+ visualConfig={visualConfig}
+ visualLayout={layout}
+ vegaConfig={vegaConfig}
+ channelScales={channelScales}
+ scale={scale}
+ />
+ )}
+ {isSpatial || (
+ <ReactVega
+ name={name}
+ vegaConfig={vegaConfig}
+ // format={format}
+ layoutMode={size.mode}
+ interactiveScale={interactiveScale}
+ geomType={geoms[0]}
+ defaultAggregate={defaultAggregated}
+ stack={stack}
+ dataSource={data}
+ rows={rows}
+ columns={columns}
+ color={color[0]}
+ theta={theta[0]}
+ radius={radius[0]}
+ shape={shape[0]}
+ opacity={opacity[0]}
+ size={sizeChannel[0]}
+ details={details}
+ text={text[0]}
+ showActions={showActions}
+ width={size.width - 12 * 4}
+ height={size.height - 12 * 4}
+ ref={ref}
+ onGeomClick={onGeomClick}
+ locale={locale}
+ useSvg={useSvg}
+ channelScales={channelScales}
+ scale={scale}
+ onReportSpec={onReportSpec}
+ displayOffset={timezoneDisplayOffset}
+ />
+ )}
+ </Resizable>
);
});
diff --git a/packages/graphic-walker/src/vis/react-vega.tsx b/packages/graphic-walker/src/vis/react-vega.tsx
index 8452ce7b..d2c728d8 100644
--- a/packages/graphic-walker/src/vis/react-vega.tsx
+++ b/packages/graphic-walker/src/vis/react-vega.tsx
@@ -287,7 +287,7 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
config: vegaConfig,
tooltip: {
theme: mediaTheme,
- },
+ },
}).then((res) => {
const container = res.view.container();
const canvas = container?.querySelector('canvas') ?? container?.querySelector('svg') ?? null;
@@ -310,12 +310,15 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
height: Math.max(rect.height - (areaHeight || height), 0),
};
if (res.view.width() === 0) {
- // is faceted view
- res.view.signal('child_width', specs[0].width - modifier.width / Math.round((areaWidth || width) / specs[0].width));
- res.view.signal('child_height', specs[0].height - modifier.height / Math.round((areaHeight || height) / specs[0].height));
+ try {
+ res.view.signal('child_width', specs[0].width - modifier.width / Math.round((areaWidth || width) / specs[0].width));
+ res.view.signal('child_height', specs[0].height - modifier.height / Math.round((areaHeight || height) / specs[0].height));
+ } catch (e) {
+ // ignore when width is just 0 because of extreamly small size
+ }
} else {
- res.view.width(specs[0].width - modifier.width);
- res.view.height(specs[0].height - modifier.height);
+ res.view.width(specs[0].width - modifier.width);
+ res.view.height(specs[0].height - modifier.height);
}
res.view.runAsync();
}
@@ -373,7 +376,6 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
tooltip: {
theme: mediaTheme,
},
-
}).then((res) => {
const container = res.view.container();
const canvas = container?.querySelector('canvas') ?? container?.querySelector('svg') ?? null;
@@ -398,15 +400,18 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
height: Math.max(rect.height - (areaHeight || height) / rowRepeatFields.length, 0),
};
if (res.view.width() === 0) {
- // is faceted view
- res.view.signal(
- 'child_width',
- specs[0].width - modifier.width / Math.round((areaWidth || width) / colRepeatFields.length / specs[0].width)
- );
- res.view.signal(
- 'child_height',
- specs[0].height - modifier.height / Math.round((areaHeight || height) / rowRepeatFields.length / specs[0].height)
- );
+ if (res.view.signal('child_width') !== undefined) {
+ // is faceted view
+ res.view.signal(
+ 'child_width',
+ specs[0].width - modifier.width / Math.round((areaWidth || width) / colRepeatFields.length / specs[0].width)
+ );
+ res.view.signal(
+ 'child_height',
+ specs[0].height -
+ modifier.height / Math.round((areaHeight || height) / rowRepeatFields.length / specs[0].height)
+ );
+ }
} else {
res.view.width(specs[0].width - modifier.width);
res.view.height(specs[0].height - modifier.height);