Skip to content

Commit

Permalink
fix: Moved check for initializing scatterplot axes to ScatterPlotTab …
Browse files Browse the repository at this point in the history
…to handle loading from URL parameters
  • Loading branch information
ShrimpCryptid committed Oct 1, 2024
1 parent 8566b09 commit 9ac5242
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
17 changes: 1 addition & 16 deletions src/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,6 @@ function Viewer(): ReactElement {
[featureThresholds, config.keepRangeBetweenDatasets]
);

/** Handle startup behaviors for tabs when changed. */
const onTabChanged = useCallback(
(key: string) => {
if (key === TabType.SCATTER_PLOT) {
// When opening scatterplot tab, plot the current feature against
// time if no x/y axis is set.
if (!scatterPlotConfig.xAxis && !scatterPlotConfig.yAxis) {
updateScatterPlotConfig({ xAxis: SCATTERPLOT_TIME_FEATURE.key, yAxis: featureKey });
}
}
updateConfig({ openTab: key as TabType });
},
[updateConfig, featureKey]
);

// DATASET LOADING ///////////////////////////////////////////////////////

const handleProgressUpdate = useCallback((complete: number, total: number): void => {
Expand Down Expand Up @@ -1070,7 +1055,7 @@ function Viewer(): ReactElement {
style={{ marginBottom: 0, width: "100%" }}
size="large"
activeKey={config.openTab}
onChange={onTabChanged}
onChange={(key) => updateConfig({ openTab: key as TabType })}
items={[
{
label: "Track plot",
Expand Down
11 changes: 10 additions & 1 deletion src/components/Tabs/ScatterPlotTab.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Tooltip } from "antd";
import { MenuItemType } from "antd/es/menu/hooks/useItems";
import Plotly, { PlotData, PlotMarker } from "plotly.js-dist-min";
import React, { memo, ReactElement, useContext, useEffect, useRef, useState, useTransition } from "react";
import React, { memo, ReactElement, useContext, useEffect, useMemo, useRef, useState, useTransition } from "react";
import styled from "styled-components";
import { Color, ColorRepresentation, HexColorString } from "three";

Expand Down Expand Up @@ -128,6 +128,15 @@ export default memo(function ScatterPlotTab(props: ScatterPlotTabProps): ReactEl
const colorRampMin = useDebounce(props.colorRampMin, 100);
const colorRampMax = useDebounce(props.colorRampMax, 100);

useMemo(() => {
if (props.scatterPlotConfig.xAxis === null && props.scatterPlotConfig.yAxis === null && props.selectedFeatureKey) {
props.updateScatterPlotConfig({
yAxis: props.selectedFeatureKey,
xAxis: SCATTERPLOT_TIME_FEATURE.key,
});
}
}, [props.selectedFeatureKey]);

// Trigger render spinner when playback starts, but only if the render is being delayed.
// If a render is allowed to happen (such as in the current-track- or current-frame-only
// range types), `isRendering` will be set to false immediately and the spinner will be hidden again.
Expand Down

0 comments on commit 9ac5242

Please sign in to comment.