Skip to content

Commit c4c0400

Browse files
committed
Add auxiliaries toggle to line vis toolbar
1 parent 7218f6d commit c4c0400

File tree

6 files changed

+67
-38
lines changed

6 files changed

+67
-38
lines changed

packages/app/src/vis-packs/core/complex/MappedComplexLineVis.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ function MappedComplexLineVis(props: Props) {
5959
yScaleType,
6060
xScaleType,
6161
complexVisType,
62-
curveType,
62+
showAux,
6363
showGrid,
64+
curveType,
6465
} = config;
6566

6667
const { phaseArrays, amplitudeArrays } = usePhaseAmplitudeArrays([
@@ -98,7 +99,12 @@ function MappedComplexLineVis(props: Props) {
9899
<>
99100
{toolbarContainer &&
100101
createPortal(
101-
<LineToolbar dataDomain={combinedDomain} isComplex config={config} />,
102+
<LineToolbar
103+
dataDomain={combinedDomain}
104+
isComplex
105+
withAux={auxValues.length > 0}
106+
config={config}
107+
/>,
102108
toolbarContainer,
103109
)}
104110

@@ -107,8 +113,6 @@ function MappedComplexLineVis(props: Props) {
107113
dataArray={dataArray}
108114
domain={safeDomain}
109115
scaleType={yScaleType}
110-
curveType={curveType}
111-
showGrid={showGrid}
112116
abscissaParams={{
113117
label: axisLabels[xDimIndex],
114118
value: numAxisArrays[xDimIndex],
@@ -120,6 +124,9 @@ function MappedComplexLineVis(props: Props) {
120124
label: auxLabels[i],
121125
array,
122126
}))}
127+
showAux={showAux}
128+
showGrid={showGrid}
129+
curveType={curveType}
123130
testid={dimMapping.toString()}
124131
/>
125132
</>

packages/app/src/vis-packs/core/line/LineToolbar.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
type ExportEntry,
1616
} from '@h5web/shared/vis-models';
1717
import { AXIS_SCALE_TYPES } from '@h5web/shared/vis-utils';
18-
import { MdGridOn } from 'react-icons/md';
18+
import { MdGridOn, MdLegendToggle } from 'react-icons/md';
1919

2020
import { INTERACTIONS_WITH_AXIAL_ZOOM } from '../utils';
2121
import { type LineConfig } from './config';
@@ -25,7 +25,8 @@ interface Props {
2525
dataDomain: Domain;
2626
isSlice?: boolean;
2727
isComplex?: boolean;
28-
disableErrors?: boolean;
28+
withErrors?: boolean;
29+
withAux?: boolean;
2930
config: LineConfig;
3031
exportEntries?: ExportEntry[];
3132
}
@@ -35,26 +36,29 @@ function LineToolbar(props: Props) {
3536
dataDomain,
3637
isSlice,
3738
isComplex,
38-
disableErrors,
39+
withErrors,
40+
withAux,
3941
config,
4042
exportEntries,
4143
} = props;
4244

4345
const {
4446
customDomain,
45-
curveType,
46-
showGrid,
4747
xScaleType,
4848
yScaleType,
4949
complexVisType,
5050
showErrors,
51+
showAux,
52+
showGrid,
53+
curveType,
5154
setCustomDomain,
52-
setCurveType,
53-
toggleGrid,
5455
setXScaleType,
5556
setYScaleType,
5657
setComplexVisType,
58+
toggleAux,
5759
toggleErrors,
60+
toggleGrid,
61+
setCurveType,
5862
} = config;
5963

6064
return (
@@ -93,13 +97,21 @@ function LineToolbar(props: Props) {
9397

9498
<Separator />
9599

96-
{!isComplex && (
100+
{withErrors && (
97101
<ToggleBtn
98102
label="Errors"
99103
Icon={ErrorsIcon}
100-
value={!disableErrors && showErrors}
104+
value={showErrors}
101105
onToggle={toggleErrors}
102-
disabled={disableErrors}
106+
/>
107+
)}
108+
109+
{withAux && (
110+
<ToggleBtn
111+
label="Aux"
112+
Icon={MdLegendToggle}
113+
value={showAux}
114+
onToggle={toggleAux}
103115
/>
104116
)}
105117

@@ -110,8 +122,6 @@ function LineToolbar(props: Props) {
110122
onToggle={toggleGrid}
111123
/>
112124

113-
<Separator />
114-
115125
<ToggleGroup
116126
role="radiogroup"
117127
ariaLabel="Curve type"

packages/app/src/vis-packs/core/line/MappedLineVis.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ function MappedLineVis(props: Props) {
7676
customDomain,
7777
yScaleType,
7878
xScaleType,
79-
curveType,
80-
showGrid,
8179
showErrors,
80+
showAux,
81+
showGrid,
82+
curveType,
8283
} = config;
8384

8485
const { shape: dims } = dataset;
@@ -153,7 +154,8 @@ function MappedLineVis(props: Props) {
153154
<LineToolbar
154155
dataDomain={combinedDomain}
155156
isSlice={selection !== undefined}
156-
disableErrors={!errors}
157+
withErrors={!!errors}
158+
withAux={auxiliaries.length > 0}
157159
config={config}
158160
exportEntries={exportEntries}
159161
/>,
@@ -165,15 +167,16 @@ function MappedLineVis(props: Props) {
165167
dataArray={dataArray}
166168
domain={safeDomain}
167169
scaleType={yScaleType}
168-
curveType={curveType}
169-
showGrid={showGrid}
170170
abscissaParams={abscissaParams}
171171
ordinateLabel={valueLabel}
172172
title={title}
173173
dtype={formatNumLikeType(dataset.type)}
174174
errorsArray={errorsArray}
175175
showErrors={showErrors}
176176
auxiliaries={auxiliaries}
177+
showAux={showAux}
178+
showGrid={showGrid}
179+
curveType={curveType}
177180
testid={dimMapping.toString()}
178181
ignoreValue={ignoreValue}
179182
/>

packages/app/src/vis-packs/core/line/config.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ export interface LineConfig {
1717
customDomain: CustomDomain;
1818
setCustomDomain: (customDomain: CustomDomain) => void;
1919

20-
curveType: CurveType;
21-
setCurveType: (type: CurveType) => void;
22-
23-
showGrid: boolean;
24-
toggleGrid: () => void;
25-
2620
xScaleType: AxisScaleType;
2721
yScaleType: AxisScaleType;
2822
setXScaleType: (type: AxisScaleType) => void;
@@ -33,6 +27,15 @@ export interface LineConfig {
3327

3428
showErrors: boolean;
3529
toggleErrors: () => void;
30+
31+
showAux: boolean;
32+
toggleAux: () => void;
33+
34+
showGrid: boolean;
35+
toggleGrid: () => void;
36+
37+
curveType: CurveType;
38+
setCurveType: (type: CurveType) => void;
3639
}
3740

3841
function createLineConfigStore() {
@@ -42,12 +45,6 @@ function createLineConfigStore() {
4245
customDomain: [null, null],
4346
setCustomDomain: (customDomain) => set({ customDomain }),
4447

45-
curveType: CurveType.LineOnly,
46-
setCurveType: (curveType) => set({ curveType }),
47-
48-
showGrid: true,
49-
toggleGrid: () => set((state) => ({ showGrid: !state.showGrid })),
50-
5148
xScaleType: ScaleType.Linear,
5249
yScaleType: ScaleType.Linear,
5350
setXScaleType: (xScaleType) => set({ xScaleType }),
@@ -58,10 +55,19 @@ function createLineConfigStore() {
5855

5956
showErrors: true,
6057
toggleErrors: () => set((state) => ({ showErrors: !state.showErrors })),
58+
59+
showAux: true,
60+
toggleAux: () => set((state) => ({ showAux: !state.showAux })),
61+
62+
showGrid: true,
63+
toggleGrid: () => set((state) => ({ showGrid: !state.showGrid })),
64+
65+
curveType: CurveType.LineOnly,
66+
setCurveType: (curveType) => set({ curveType }),
6167
}),
6268
{
6369
name: 'h5web:line',
64-
version: 6,
70+
version: 7,
6571
},
6672
),
6773
);

packages/lib/src/vis/line/DataCurve.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function DataCurve(props: Props) {
3535
abscissas,
3636
ordinates,
3737
errors,
38-
showErrors,
38+
showErrors = true,
3939
color,
4040
curveType = CurveType.LineOnly,
4141
glyphType = GlyphType.Cross,

packages/lib/src/vis/line/LineVis.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ interface Props extends ClassStyleAttrs {
2828
dataArray: NdArray<NumArray>;
2929
domain: Domain | undefined;
3030
scaleType?: AxisScaleType;
31-
curveType?: CurveType;
32-
showGrid?: boolean;
3331
abscissaParams?: AxisParams;
3432
ordinateLabel?: string;
3533
title?: string;
3634
dtype?: string;
3735
errorsArray?: NdArray<NumArray>;
3836
showErrors?: boolean;
3937
auxiliaries?: AuxiliaryParams[];
38+
showAux?: boolean;
39+
showGrid?: boolean;
40+
curveType?: CurveType;
4041
renderTooltip?: (data: TooltipData) => ReactElement;
4142
children?: ReactNode;
4243
interactions?: DefaultInteractionsConfig;
@@ -56,8 +57,9 @@ function LineVis(props: Props) {
5657
title,
5758
dtype,
5859
errorsArray,
59-
showErrors = false,
60+
showErrors = true,
6061
auxiliaries = [],
62+
showAux = true,
6163
renderTooltip,
6264
children,
6365
interactions,
@@ -191,6 +193,7 @@ function LineVis(props: Props) {
191193
color={auxColors[i % auxColors.length]}
192194
curveType={curveType}
193195
ignoreValue={ignoreValue}
196+
visible={showAux}
194197
/>
195198
))}
196199

0 commit comments

Comments
 (0)