An open source alternative to Tableau. Embeddable visual analytic
TypeScript bidatadata-analysisdata-miningdata-visualizationedak6skanarieslow-codepivot-tablereacttableautableau-alternativetypescriptvegavega-litevisualization
fix: resizable condition bug
ObservedObservere91c7162dc98
diff --git a/packages/graphic-walker/src/renderer/index.tsx b/packages/graphic-walker/src/renderer/index.tsxindex cb389423..2c8291cf 100644--- a/packages/graphic-walker/src/renderer/index.tsx+++ b/packages/graphic-walker/src/renderer/index.tsx@@ -1,44 +1,49 @@-import { runInAction, toJS } from 'mobx';-import { observer } from 'mobx-react-lite';-import { Resizable } from 're-resizable';-import React, { useState, useCallback, useEffect, useRef, forwardRef } from 'react';-import { applyFilter } from '../services';-import { useGlobalStore } from '../store';-import ReactVega, { IReactVegaHandler } from '../vis/react-vega';+import { runInAction, toJS } from "mobx";+import { observer } from "mobx-react-lite";+import { Resizable } from "re-resizable";+import React, { useState, useCallback, useEffect, useRef, forwardRef } from "react";+import { applyFilter } from "../services";+import { useGlobalStore } from "../store";+import ReactVega, { IReactVegaHandler } from "../vis/react-vega";--const ReactiveRenderer = forwardRef<IReactVegaHandler, { themeKey?: 'vega' | 'g2' }>(function ReactiveRenderer ({ themeKey }, ref) {+const ReactiveRenderer = forwardRef<IReactVegaHandler, { themeKey?: "vega" | "g2" }>(function ReactiveRenderer(+ { themeKey },+ ref+) {const { vizStore, commonStore } = useGlobalStore();const { draggableFieldState, visualConfig } = vizStore;const { geoms, interactiveScale, defaultAggregated, stack, showActions, size, exploration } = visualConfig;const { currentDataset } = commonStore;const { filters } = draggableFieldState;- const rows = toJS(draggableFieldState.rows)- const columns = toJS(draggableFieldState.columns)- const color = toJS(draggableFieldState.color)- const opacity = toJS(draggableFieldState.opacity)- const shape = toJS(draggableFieldState.shape)- const theta = toJS(draggableFieldState.theta)- const radius = toJS(draggableFieldState.radius)- const sizeChannel = toJS(draggableFieldState.size)+ const rows = toJS(draggableFieldState.rows);+ const columns = toJS(draggableFieldState.columns);+ const color = toJS(draggableFieldState.color);+ const opacity = toJS(draggableFieldState.opacity);+ const shape = toJS(draggableFieldState.shape);+ const theta = toJS(draggableFieldState.theta);+ const radius = toJS(draggableFieldState.radius);+ const sizeChannel = toJS(draggableFieldState.size);- const rowLeftFacetFields = rows.slice(0, -1).filter(f => f.analyticType === 'dimension');- const colLeftFacetFields = columns.slice(0, -1).filter(f => f.analyticType === 'dimension');+ const rowLeftFacetFields = rows.slice(0, -1).filter((f) => f.analyticType === "dimension");+ const colLeftFacetFields = columns.slice(0, -1).filter((f) => f.analyticType === "dimension");const hasFacet = rowLeftFacetFields.length > 0 || colLeftFacetFields.length > 0;- const shouldTriggerMenu = exploration.mode === 'none';-- const handleGeomClick = useCallback((values: any, e: any) => {- if (shouldTriggerMenu) {- e.stopPropagation();- runInAction(() => {- commonStore.showEmbededMenu([e.pageX, e.pageY])- commonStore.setFilters(values);- });- }- }, [shouldTriggerMenu]);+ const shouldTriggerMenu = exploration.mode === "none";++ const handleGeomClick = useCallback(+ (values: any, e: any) => {+ if (shouldTriggerMenu) {+ e.stopPropagation();+ runInAction(() => {+ commonStore.showEmbededMenu([e.pageX, e.pageY]);+ commonStore.setFilters(values);+ });+ }+ },+ [shouldTriggerMenu]+ );// apply filtersconst { dataSource } = currentDataset;@@ -54,14 +59,14 @@ const ReactiveRenderer = forwardRef<IReactVegaHandler, { themeKey?: 'vega' | 'g2const p = filters.length === 0 ? Promise.resolve(dataSource) : applyFilter(dataSource, filters);pendingPromiseRef.current = p;- p.then(d => {+ p.then((d) => {if (p !== pendingPromiseRef.current) {// This promise is out-of-datereturn;}setData(d);- }).catch(err => {+ }).catch((err) => {console.error(err);});@@ -69,45 +74,63 @@ const ReactiveRenderer = forwardRef<IReactVegaHandler, { themeKey?: 'vega' | 'g2pendingPromiseRef.current = null;};}, [dataSource, filters]);-- return <Resizable className={(size.mode === 'fixed' && !hasFacet) ? "border-blue-400 border-2 overflow-hidden" : ""}- style={{ padding: '12px' }}- onResizeStop={(e, direction, ref, d) => {- vizStore.setChartLayout({- mode: 'fixed',- width: size.width + d.width,- height: size.height + d.height- })- }}- size={{- width: size.width + 'px',- height: size.height + 'px',- }}>- <ReactVega- 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]}- showActions={showActions}- width={size.width - 12 * 4}- height={size.height - 12 * 4}- ref={ref}- brushEncoding={exploration.mode === 'brush' ? exploration.brushDirection : 'none'}- selectEncoding={exploration.mode === 'point' ? 'default' : 'none'}- onGeomClick={handleGeomClick}- themeKey={themeKey}- />- </Resizable>+ const enableResize = size.mode === "fixed" && !hasFacet;+ return (+ <Resizable+ className={enableResize ? "border-blue-400 border-2 overflow-hidden" : ""}+ style={{ padding: "12px" }}+ onResizeStop={(e, direction, ref, d) => {+ vizStore.setChartLayout({+ mode: "fixed",+ width: size.width + d.width,+ height: size.height + d.height,+ });+ }}+ enable={+ enableResize+ ? undefined+ : {+ top: false,+ right: false,+ bottom: false,+ left: false,+ topRight: false,+ bottomRight: false,+ bottomLeft: false,+ topLeft: false,+ }+ }+ size={{+ width: size.width + "px",+ height: size.height + "px",+ }}+ >+ <ReactVega+ 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]}+ showActions={showActions}+ width={size.width - 12 * 4}+ height={size.height - 12 * 4}+ ref={ref}+ brushEncoding={exploration.mode === "brush" ? exploration.brushDirection : "none"}+ selectEncoding={exploration.mode === "point" ? "default" : "none"}+ onGeomClick={handleGeomClick}+ themeKey={themeKey}+ />+ </Resizable>+ );});export default observer(ReactiveRenderer);