An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
chore: make sidebar resizeable (#217)
islxyqwebc1e55d56fcf
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsxindex 2268132b..4b79c4e3 100644--- a/packages/graphic-walker/src/App.tsx+++ b/packages/graphic-walker/src/App.tsx@@ -44,6 +44,7 @@ import { GWGlobalConfig } from './vis/theme';import { useCurrentMediaTheme } from './utils/media';import { parseErrorMessage } from './utils';import { VizEmbedMenu } from './components/embedMenu';+import SideReisze from './components/side-resize';export interface BaseVizProps {i18nLang?: string;@@ -178,15 +179,25 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {<LogPanel /><BinPanel />{vizStore.showGeoJSONConfigPanel && <GeoConfigPanel geoList={props.geoList} />}- <div className="sm:grid sm:grid-cols-12 xl:grid-cols-6">- <div className="sm:col-span-3 xl:col-span-1">+ <div className="sm:flex">+ <SideReisze+ defaultWidth={240}+ handleWidth={4}+ className="min-w-[100%] max-w-full sm:min-w-[96px] sm:max-w-[35%] flex-shrink-0"+ handlerClassName="hidden sm:block"+ ><DatasetFields />- </div>- <div className="sm:col-span-2 xl:col-span-1">+ </SideReisze>+ <SideReisze+ defaultWidth={180}+ handleWidth={4}+ className="min-w-[100%] max-w-full sm:min-w-[120px] sm:max-w-[30%] flex-shrink-0"+ handlerClassName="hidden sm:block"+ ><FilterField /><AestheticFields />- </div>- <div className="sm:col-span-7 xl:col-span-4">+ </SideReisze>+ <div className="flex-1"><div><PosFields /></div>diff --git a/packages/graphic-walker/src/components/side-resize.tsx b/packages/graphic-walker/src/components/side-resize.tsxnew file mode 100644index 00000000..fc80f85a--- /dev/null+++ b/packages/graphic-walker/src/components/side-resize.tsx@@ -0,0 +1,45 @@+import React, { useRef, useState } from 'react';++export default function SideReisze(props: {+ defaultWidth: number;+ handleWidth?: number;+ className?: string;+ handlerClassName?: string;+ children?: React.ReactNode | Iterable<React.ReactNode>;+}) {+ const sidebarRef = useRef<HTMLDivElement>(null);+ const [isResizing, setIsResizing] = useState(false);+ const [sidebarWidth, setSidebarWidth] = useState(props.defaultWidth);+ const startResizing = React.useCallback(() => {+ setIsResizing(true);+ }, []);++ const stopResizing = React.useCallback(() => {+ setIsResizing(false);+ }, []);++ const resize = React.useCallback(+ (mouseMoveEvent) => {+ if (isResizing) {+ setSidebarWidth(mouseMoveEvent.clientX - sidebarRef.current!.getBoundingClientRect().left);+ }+ },+ [isResizing]+ );++ React.useEffect(() => {+ window.addEventListener('mousemove', resize);+ window.addEventListener('mouseup', stopResizing);+ return () => {+ window.removeEventListener('mousemove', resize);+ window.removeEventListener('mouseup', stopResizing);+ };+ }, [resize, stopResizing]);++ return (+ <div className={`relative ${props.className}`} style={{ width: sidebarWidth }} ref={sidebarRef}>+ {props.children}+ <div className={`absolute right-0 inset-y-0 cursor-col-resize ${props.handlerClassName}`} style={{ width: props.handleWidth ?? 6 }} onMouseDown={startResizing}></div>+ </div>+ );+}diff --git a/packages/graphic-walker/src/fields/datasetFields/index.tsx b/packages/graphic-walker/src/fields/datasetFields/index.tsxindex e5d58299..107b3b7a 100644--- a/packages/graphic-walker/src/fields/datasetFields/index.tsx+++ b/packages/graphic-walker/src/fields/datasetFields/index.tsx@@ -6,7 +6,7 @@ import DimFields from "./dimFields";import MeaFields from "./meaFields";const DSContainer = styled.div`- @media (min-width: 768px) {+ @media (min-width: 640px) {height: 680px;}`@@ -15,7 +15,7 @@ const DatasetFields: React.FC = (props) => {const { t } = useTranslation("translation", { keyPrefix: "main.tabpanel.DatasetFields" });return (- <DSContainer className="p-1 m-0.5 border border-gray-200 dark:border-gray-700 flex md:flex-col" style={{ paddingBlock: 0, paddingInline: '0.6em' }}>+ <DSContainer className="p-1 m-0.5 border border-gray-200 dark:border-gray-700 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">diff --git a/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx b/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsxindex dcec0d3a..37ffbdd9 100644--- a/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx+++ b/packages/graphic-walker/src/fields/encodeFields/singleEncodeEditor.tsx@@ -82,9 +82,9 @@ const SingleEncodeEditor: React.FC<SingleEncodeEditorProps> = (props) => {onSelect={(keys) => {vizStore.setVisualConfig('folds', keys);}}- className="flex-1"+ className="flex-1 truncate">- <span className="flex-1 truncate">{channelItem.name}</span>+ {channelItem.name}</SelectContext>)}{channelItem.fid !== MEA_KEY_ID && <span className="flex-1 truncate">{channelItem.name}</span>}{' '}