Skip to content

Commit 334028e

Browse files
fix(hparams): keep scatter matrix axis and color choices across view switches
The scatter matrix held its picked dimensions and color-by in local state, so switching to the table and back unmounted the view and reset the axes to the default first six. Lift the selection into HParamsPane and make HParamsSplom a controlled component so the choice persists while the view stays lazily mounted.
1 parent 30cc550 commit 334028e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

js/panes/HParamsPane.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ var HParamsPane = (props) => {
3838
const { content } = props;
3939
const data = readContent(content);
4040
const [view, setView] = useState('table');
41+
const [splomDims, setSplomDims] = useState(null);
42+
const [splomColorBy, setSplomColorBy] = useState(null);
4143

4244
const handleDownload = () => {
4345
let blob = new Blob([JSON.stringify(content)], {
@@ -104,6 +106,10 @@ var HParamsPane = (props) => {
104106
paramKeys={data.paramKeys}
105107
metricKeys={data.metricKeys}
106108
tagKeys={data.tagKeys}
109+
selectedDims={splomDims}
110+
onSelectedDims={setSplomDims}
111+
colorBy={splomColorBy}
112+
onColorBy={setSplomColorBy}
107113
/>
108114
) : (
109115
<HParamsTable

js/panes/hparams/HParamsSplom.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import TreeSelect from 'rc-tree-select';
11-
import React, { useEffect, useMemo, useRef, useState } from 'react';
11+
import React, { useEffect, useMemo, useRef } from 'react';
1212

1313
import {
1414
buildColumns,
@@ -73,7 +73,16 @@ function downloadSnapshot(gd) {
7373
});
7474
}
7575

76-
const HParamsSplom = ({ records, paramKeys, metricKeys, tagKeys }) => {
76+
const HParamsSplom = ({
77+
records,
78+
paramKeys,
79+
metricKeys,
80+
tagKeys,
81+
selectedDims,
82+
onSelectedDims,
83+
colorBy,
84+
onColorBy,
85+
}) => {
7786
const plotRef = useRef(null);
7887
const prevDimCount = useRef(0);
7988

@@ -86,9 +95,6 @@ const HParamsSplom = ({ records, paramKeys, metricKeys, tagKeys }) => {
8695
[records, columns]
8796
);
8897

89-
const [selectedDims, setSelectedDims] = useState(null);
90-
const [colorBy, setColorBy] = useState(null);
91-
9298
const effectiveDims = useMemo(() => {
9399
const validIds = new Set(numericCols.map((c) => c.id));
94100
let ids = (selectedDims || []).filter((id) => validIds.has(id));
@@ -251,7 +257,7 @@ const HParamsSplom = ({ records, paramKeys, metricKeys, tagKeys }) => {
251257
}, [records, columns, effectiveDims, effectiveColorBy]);
252258

253259
const handleDims = (value) => {
254-
setSelectedDims(Array.isArray(value) ? value.slice(0, MAX_DIMS) : []);
260+
onSelectedDims(Array.isArray(value) ? value.slice(0, MAX_DIMS) : []);
255261
};
256262

257263
if (!hasPlot) {
@@ -296,7 +302,7 @@ const HParamsSplom = ({ records, paramKeys, metricKeys, tagKeys }) => {
296302
treeDefaultExpandAll
297303
dropdownMatchSelectWidth={false}
298304
treeData={treeData}
299-
onChange={(value) => setColorBy(value || null)}
305+
onChange={(value) => onColorBy(value || null)}
300306
aria-label="Color scatter matrix by"
301307
/>
302308
</span>

0 commit comments

Comments
 (0)