Skip to content

An open source alternative to Tableau. Embeddable visual analytic

feat(visualSettings): liteForm -> toolbar

kyusho78702a34da1e
diff --git a/packages/graphic-walker/src/components/sizeSetting.tsx b/packages/graphic-walker/src/components/sizeSetting.tsx
index caede99f..6414cccf 100644
--- a/packages/graphic-walker/src/components/sizeSetting.tsx
+++ b/packages/graphic-walker/src/components/sizeSetting.tsx
@@ -1,5 +1,5 @@
import { ArrowsPointingOutIcon, XMarkIcon } from "@heroicons/react/24/outline";
-import React, { useState, useEffect, useRef } from "react";
+import React, { useState, useEffect } from "react";
import { useTranslation } from 'react-i18next';
@@ -10,6 +10,45 @@ interface SizeSettingProps {
height: number;
}
+export const ResizeDialog: React.FC<SizeSettingProps> = props => {
+ const { onWidthChange, onHeightChange, width, height, children } = props
+ const { t } = useTranslation('translation', { keyPrefix: 'main.tabpanel.settings.size_setting' });
+
+ return <>
+ {children}
+ <div className="mt-4 w-60">
+ <input className="w-full h-2 bg-blue-100 appearance-none"
+ style={{ cursor: 'ew-resize' }}
+ type="range"
+ name="width"
+ value={Math.sqrt(width / 1000)}
+ min="0" max="1" step="0.01"
+ onChange={(e) => {
+ onWidthChange(Math.round(Number(e.target.value) ** 2 * 1000))
+ }}
+ />
+ <output className="text-sm ml-1" htmlFor="width">
+ {`${t('width')}: ${width}`}
+ </output>
+ </div>
+ <div className=" mt-2">
+ <input className="w-full h-2 bg-blue-100 appearance-none"
+ style={{ cursor: 'ew-resize' }}
+ type="range"
+ name="height"
+ value={Math.sqrt(height / 1000)}
+ min="0" max="1" step="0.01"
+ onChange={(e) => {
+ onHeightChange(Math.round(Number(e.target.value) ** 2 * 1000))
+ }}
+ />
+ <output className="text-sm ml-1" htmlFor="height">
+ {`${t('height')}: ${height}`}
+ </output>
+ </div>
+ </>
+};
+
const SizeSetting: React.FC<SizeSettingProps> = props => {
const { onWidthChange, onHeightChange, width, height } = props
const [show, setShow] = useState<boolean>(false);
@@ -48,54 +87,20 @@ const SizeSetting: React.FC<SizeSettingProps> = props => {
}}
className="w-4 h-4 inline-block mr-0.5 text-gray-900"
/>
- {
- show && <div role="dialog" className="absolute z-auto bg-white p-4 border border-gray-200 shadow cursor-default" onClick={e => e.stopPropagation()} style={{ zIndex: 25535 }}>
- <div>
- <XMarkIcon
- className="text-gray-900 absolute right-2 top-2 w-4 cursor-pointer hover:bg-red-100"
- role="button"
- tabIndex={0}
- aria-label="close"
- onClick={(e) => {
- setShow(false);
- e.stopPropagation();
- }}
- />
- </div>
-
- <div className="mt-4 w-60">
- <input className="w-full h-2 bg-blue-100 appearance-none"
- style={{ cursor: 'ew-resize' }}
- type="range"
- name="width"
- value={Math.sqrt(width / 1000)}
- min="0" max="1" step="0.01"
- onChange={(e) => {
- onWidthChange(Math.round(Number(e.target.value) ** 2 * 1000))
- }}
- />
- <output className="text-sm ml-1" htmlFor="width">
- {`${t('width')}: ${width}`}
- </output>
- </div>
- <div className=" mt-2">
- <input className="w-full h-2 bg-blue-100 appearance-none"
- style={{ cursor: 'ew-resize' }}
- type="range"
- name="height"
- value={Math.sqrt(height / 1000)}
- min="0" max="1" step="0.01"
- onChange={(e) => {
- onHeightChange(Math.round(Number(e.target.value) ** 2 * 1000))
- }}
- />
- <output className="text-sm ml-1" htmlFor="height">
- {`${t('height')}: ${height}`}
- </output>
- </div>
-
+ {show && <ResizeDialog {...props}>
+ <div>
+ <XMarkIcon
+ className="text-gray-900 absolute right-2 top-2 w-4 cursor-pointer hover:bg-red-100"
+ role="button"
+ tabIndex={0}
+ aria-label="close"
+ onClick={(e) => {
+ setShow(false);
+ e.stopPropagation();
+ }}
+ />
</div>
- }
+ </ResizeDialog>}
</div>
}
diff --git a/packages/graphic-walker/src/visualSettings/index.tsx b/packages/graphic-walker/src/visualSettings/index.tsx
index 7f89ba44..edd22967 100644
--- a/packages/graphic-walker/src/visualSettings/index.tsx
+++ b/packages/graphic-walker/src/visualSettings/index.tsx
@@ -2,7 +2,6 @@ import {
ArrowUturnLeftIcon,
BarsArrowDownIcon,
BarsArrowUpIcon,
- ChevronDownIcon,
PhotoIcon,
ArrowPathIcon,
ArrowsPointingOutIcon,
@@ -10,13 +9,19 @@ import {
Square3Stack3DIcon,
StopIcon,
ArrowUturnRightIcon,
+ LockClosedIcon,
+ LockOpenIcon,
+ ViewfinderCircleIcon,
+ ChatBubbleBottomCenterTextIcon,
+ PaintBrushIcon,
+ CursorArrowRaysIcon,
+ WrenchIcon,
} from '@heroicons/react/24/outline';
import { observer } from 'mobx-react-lite';
import React, { useMemo } from 'react';
import styled from 'styled-components'
import { useTranslation } from 'react-i18next';
-import { LiteForm } from '../components/liteForm';
-import SizeSetting from '../components/sizeSetting';
+import { ResizeDialog } from '../components/sizeSetting';
import { GEMO_TYPES, STACK_MODE, CHART_LAYOUT_TYPE } from '../config';
import { useGlobalStore } from '../store';
import { IStackMode, EXPLORATION_TYPES, IBrushDirection, BRUSH_DIRECTIONS } from '../interfaces';
@@ -57,17 +62,26 @@ const Invisible = styled.div`
position: absolute;
`;
+const FormContainer = styled.div`
+ margin: 2px;
+ border-radius: 1.2px;
+ padding: 0.5em;
+`;
+
interface IVisualSettings {
rendererHandler?: React.RefObject<IReactVegaHandler>;
}
const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler }) => {
const { vizStore } = useGlobalStore();
- const { visualConfig, sortCondition, canUndo, canRedo } = vizStore;
+ const { visualConfig, canUndo, canRedo } = vizStore;
const { t: tGlobal } = useTranslation();
const { t } = useTranslation('translation', { keyPrefix: 'main.tabpanel.settings' });
- const { defaultAggregated, geoms: [markType], stack, interactiveScale } = visualConfig;
+ const {
+ defaultAggregated, geoms: [markType], stack, interactiveScale, size: { mode: sizeMode, width, height },
+ exploration: { mode: explorationMode, brushDirection }, showActions,
+ } = visualConfig;
const items = useMemo<ToolbarItemProps[]>(() => {
return [
@@ -160,27 +174,147 @@ const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler }) => {
{
key: 'transpose',
label: t('button.transpose'),
- icon: () => <ArrowPathIcon />,
+ icon: ArrowPathIcon,
onClick: () => vizStore.transpose(),
},
{
key: 'sort:asc',
label: t('button.ascending'),
- icon: () => <BarsArrowUpIcon />,
+ icon: BarsArrowUpIcon,
onClick: () => vizStore.applyDefaultSort('ascending'),
},
{
key: 'sort:dec',
label: t('button.descending'),
- icon: () => <BarsArrowDownIcon />,
+ icon: BarsArrowDownIcon,
onClick: () => vizStore.applyDefaultSort('descending'),
},
'-',
+ {
+ key: 'scale',
+ icon: ArrowsPointingOutIcon,
+ label: tGlobal(`constant.layout_type.__enum__`),
+ options: CHART_LAYOUT_TYPE.map(g => ({
+ key: g,
+ label: tGlobal(`constant.layout_type.${g}`),
+ icon: g === 'auto' ? LockClosedIcon : LockOpenIcon,
+ })),
+ value: sizeMode,
+ onSelect: key => {
+ vizStore.setChartLayout({ mode: key as 'fixed' | 'auto' });
+ },
+ form: (
+ <FormContainer>
+ <ResizeDialog
+ width={width}
+ height={height}
+ onHeightChange={(v) => {
+ vizStore.setChartLayout({
+ mode: "fixed",
+ height: v
+ });
+ }}
+ onWidthChange={(v) => {
+ vizStore.setChartLayout({
+ mode: "fixed",
+ width: v
+ });
+ }}
+ />
+ </FormContainer>
+ ),
+ },
+ '-',
+ {
+ key: 'exploration_mode',
+ icon: ViewfinderCircleIcon,
+ label: tGlobal(`constant.exploration_mode.__enum__`),
+ options: EXPLORATION_TYPES.map(g => ({
+ key: g,
+ label: tGlobal(`constant.exploration_mode.${g}`),
+ icon: {
+ none: ChatBubbleBottomCenterTextIcon,
+ brush: PaintBrushIcon,
+ point: CursorArrowRaysIcon,
+ }[g],
+ })),
+ value: explorationMode,
+ onSelect: key => {
+ vizStore.setExploration({
+ mode: key as (typeof EXPLORATION_TYPES)[number]
+ });
+ },
+ form: explorationMode === 'brush' ? (
+ <FormContainer>
+ <label
+ id="dropdown:brush_mode:label"
+ htmlFor="dropdown:brush_mode"
+ >
+ {tGlobal(`constant.brush_mode.__enum__`)}
+ </label>
+ <select
+ className="border border-gray-500 rounded-sm text-xs pt-0.5 pb-0.5 pl-2 pr-2 cursor-pointer"
+ id="dropdown:brush_mode"
+ aria-describedby="dropdown:brush_mode:label"
+ disabled={explorationMode !== 'brush'}
+ aria-disabled={explorationMode !== 'brush'}
+ value={brushDirection}
+ onChange={e => {
+ vizStore.setExploration({
+ brushDirection: e.target.value as IBrushDirection
+ });
+ }}
+ >
+ {BRUSH_DIRECTIONS.map(g => (
+ <option
+ key={g}
+ value={g}
+ className="cursor-pointer"
+ aria-selected={brushDirection === g}
+ >
+ {tGlobal(`constant.brush_mode.${g}`)}
+ </option>
+ ))}
+ </select>
+ </FormContainer>
+ ) : undefined,
+ },
+ {
+ key: 'debug',
+ label: t('toggle.debug'),
+ icon: WrenchIcon,
+ checked: showActions,
+ onChange: checked => {
+ vizStore.setVisualConfig('showActions', checked);
+ },
+ },
+ {
+ key: 'export_chart',
+ label: t('button.export_chart'),
+ icon: PhotoIcon,
+ form: (
+ <FormContainer>
+ <button
+ className="text-xs min-w-96 w-full pt-1 pb-1 pl-6 pr-6 bg-white hover:bg-gray-200"
+ aria-label={t('button.export_chart_as', { type: 'png' })}
+ onClick={() => rendererHandler?.current?.downloadPNG()}
+ >
+ {t('button.export_chart_as', { type: 'png' })}
+ </button>
+ <button
+ className="text-xs min-w-96 w-full pt-1 pb-1 pl-6 pr-6 bg-white hover:bg-gray-200"
+ aria-label={t('button.export_chart_as', { type: 'svg' })}
+ onClick={() => rendererHandler?.current?.downloadSVG()}
+ >
+ {t('button.export_chart_as', { type: 'svg' })}
+ </button>
+ </FormContainer>
+ ),
+ },
];
- }, [vizStore, canUndo, canRedo, defaultAggregated, markType, stack, interactiveScale]);
+ }, [vizStore, canUndo, canRedo, defaultAggregated, markType, stack, interactiveScale, sizeMode, width, height, explorationMode, brushDirection, showActions]);
- return <>
- <div style={{ margin: '0.38em 0.2em' }}>
+ return <div style={{ margin: '0.38em 0.2em' }}>
<Toolbar
items={items}
styles={{
@@ -198,189 +332,6 @@ const VisualSettings: React.FC<IVisualSettings> = ({ rendererHandler }) => {
}}
/>
</div>
- <LiteContainer>
- <LiteForm style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center' }}>
- <div className="item">
- <label
- id="dropdown:layout_type:label"
- htmlFor="dropdown:layout_type"
- >
- {tGlobal(`constant.layout_type.__enum__`)}
- </label>
- <select
- className="border border-gray-500 rounded-sm text-xs pt-0.5 pb-0.5 pl-2 pr-2 cursor-pointer"
- id="dropdown:layout_type"
- aria-describedby="dropdown:layout_type:label"
- value={visualConfig.size.mode}
- onChange={(e) => {
- // vizStore.setVisualConfig('geoms', [e.target.value]);
- vizStore.setChartLayout({
- mode: e.target.value as any
- })
- }}
- >
- {CHART_LAYOUT_TYPE.map(g => (
- <option
- key={g}
- value={g}
- className="cursor-pointer"
- aria-selected={visualConfig.size.mode === g}
- >
- {tGlobal(`constant.layout_type.${g}`)}
- </option>
- ))}
- </select>
- </div>
- <div className="item hover:bg-yellow-100">
- <SizeSetting
- width={visualConfig.size.width}
- height={visualConfig.size.height}
- onHeightChange={(v) => {
- vizStore.setChartLayout({
- mode: "fixed",
- height: v
- })
- }}
- onWidthChange={(v) => {
- vizStore.setChartLayout({
- mode: "fixed",
- width: v
- })
- }}
- />
- <label
- className="text-xs text-color-gray-700 ml-2"
- htmlFor="button:size_setting"
- id="button:size_setting:label"
- >
- {t('size')}
- </label>
- </div>
- <div className="item">
- <label
- id="dropdown:exploration_mode:label"
- htmlFor="dropdown:exploration_mode"
- >
- {tGlobal(`constant.exploration_mode.__enum__`)}
- </label>
- <select
- className="border border-gray-500 rounded-sm text-xs pt-0.5 pb-0.5 pl-2 pr-2 cursor-pointer"
- id="dropdown:exploration_mode"
- aria-describedby="dropdown:exploration_mode:label"
- value={visualConfig.exploration.mode}
- onChange={e => {
- vizStore.setExploration({
- mode: e.target.value as (typeof EXPLORATION_TYPES)[number]
- });
- }}
- >
- {EXPLORATION_TYPES.map(g => (
- <option
- key={g}
- value={g}
- className="cursor-pointer"
- aria-selected={visualConfig.exploration.mode === g}
- >
- {tGlobal(`constant.exploration_mode.${g}`)}
- </option>
- ))}
- </select>
- </div>
- <div className="item" style={{ opacity: visualConfig.exploration.mode !== 'brush' ? 0.3 : undefined }}>
- <label
- id="dropdown:brush_mode:label"
- htmlFor="dropdown:brush_mode"
- >
- {tGlobal(`constant.brush_mode.__enum__`)}
- </label>
- <select
- className="border border-gray-500 rounded-sm text-xs pt-0.5 pb-0.5 pl-2 pr-2 cursor-pointer"
- id="dropdown:brush_mode"
- aria-describedby="dropdown:brush_mode:label"
- disabled={visualConfig.exploration.mode !== 'brush'}
- aria-disabled={visualConfig.exploration.mode !== 'brush'}
- value={visualConfig.exploration.brushDirection}
- onChange={e => {
- vizStore.setExploration({
- brushDirection: e.target.value as IBrushDirection
- });
- }}
- >
- {BRUSH_DIRECTIONS.map(g => (
- <option
- key={g}
- value={g}
- className="cursor-pointer"
- aria-selected={visualConfig.exploration.brushDirection === g}
- >
- {tGlobal(`constant.brush_mode.${g}`)}
- </option>
- ))}
- </select>
- </div>
- <div className="item">
- <input
- type="checkbox"
- checked={visualConfig.showActions}
- id="toggle:debug"
- aria-describedby="toggle:debug:label"
- className="cursor-pointer"
- onChange={(e) => {
- vizStore.setVisualConfig('showActions', e.target.checked);
- }}
- />
- <label
- className="text-xs text-color-gray-700 ml-2 cursor-pointer"
- id="toggle:debug:label"
- htmlFor="toggle:debug"
- >
- {t('toggle.debug')}
- </label>
- </div>
- <div className='item'>
- <label
- className="text-xs text-color-gray-700 mr-2"
- htmlFor="button:transpose"
- id="button:transpose:label"
- >
- {t('button.export_chart')}
- </label>
- <PhotoIcon
- className="w-4 inline-block cursor-pointer"
- role="button"
- tabIndex={0}
- id="button:export_chart"
- aria-describedby="button:export_chart:label"
- xlinkTitle={t('button.export_chart')}
- aria-label={t('button.export_chart')}
- onClick={() => rendererHandler?.current?.downloadPNG()}
- />
- <div className="menu-root flex flex-col items-center justify-center">
- <ChevronDownIcon
- className="w-4 h-3 inline-block mr-1 cursor-pointer trigger"
- role="button"
- tabIndex={0}
- />
- <div>
- <button
- className="text-xs min-w-96 w-full pt-1 pb-1 pl-6 pr-6 bg-white hover:bg-gray-200"
- aria-label={t('button.export_chart_as', { type: 'png' })}
- onClick={() => rendererHandler?.current?.downloadPNG()}
- >
- {t('button.export_chart_as', { type: 'png' })}
- </button>
- <button
- className="text-xs min-w-96 w-full pt-1 pb-1 pl-6 pr-6 bg-white hover:bg-gray-200"
- aria-label={t('button.export_chart_as', { type: 'svg' })}
- onClick={() => rendererHandler?.current?.downloadSVG()}
- >
- {t('button.export_chart_as', { type: 'svg' })}
- </button>
- </div>
- </div>
- </div>
- </LiteForm>
- </LiteContainer></>
}
export default observer(VisualSettings);
\ No newline at end of file