Skip to content

Commit

Permalink
fix(vis-type: scatter): Fix SPLOM stats calculation and cleanup (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvmartinweigl authored Oct 18, 2024
1 parent 3bcc4eb commit f67d209
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/demo/MainApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export function MainApp() {
shape: null,
dragMode: EScatterSelectSettings.RECTANGLE,
alphaSliderVal: 1,
sizeSliderVal: 5,
showLabels: ELabelingOptions.SELECTED,
showLabelLimit: 20,
regressionLineOptions: {
Expand Down
5 changes: 0 additions & 5 deletions src/vis/scatter/Regression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,6 @@ const methods = {
},
};

const regressionMethodsMapping = {
[ERegressionLineType.LINEAR]: 'linear',
[ERegressionLineType.POLYNOMIAL]: 'polynomial',
};

export const fitRegressionLine = (
data: { x: number[]; y: number[] },
method: ERegressionLineType,
Expand Down
13 changes: 6 additions & 7 deletions src/vis/scatter/ScatterVis.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-compiler/react-compiler */
import { useElementSize, useResizeObserver, useWindowEvent } from '@mantine/hooks';
import { useElementSize, useWindowEvent } from '@mantine/hooks';
import { Center, Group, Stack, Switch, Tooltip, ScrollArea } from '@mantine/core';
import * as React from 'react';
import cloneDeep from 'lodash/cloneDeep';
Expand All @@ -14,8 +14,6 @@ import { EColumnTypes, ENumericalColorScaleType, EScatterSelectSettings, ICommon
import { BrushOptionButtons } from '../sidebar/BrushOptionButtons';
import { ERegressionLineType, IInternalScatterConfig, IRegressionResult } from './interfaces';
import { defaultRegressionLineStyle, fetchColumnData, regressionToAnnotation } from './utils';
import { getLabelOrUnknown } from '../general/utils';
import { truncateText } from '../general/layoutUtils';
import { fitRegressionLine } from './Regression';
import { useDataPreparation } from './useDataPreparation';
import { InvalidCols } from '../general/InvalidCols';
Expand Down Expand Up @@ -192,7 +190,7 @@ export function ScatterVis({
},
],
results: [curveFit],
annotations: [regressionToAnnotation(curveFit, 3, 'x', 'y')],
annotations: config.regressionLineOptions.showStats !== false ? [regressionToAnnotation(curveFit, 3, 'x', 'y')] : [],
};
}
}
Expand Down Expand Up @@ -232,9 +230,9 @@ export function ScatterVis({
const results: IRegressionResult[] = [];
const plotlyShapes: Partial<PlotlyTypes.Shape>[] = [];
// eslint-disable-next-line guard-for-in
splom.xyPairs.forEach((pair, i) => {
splom.xyPairs.forEach((pair) => {
const curveFit = fitRegressionLine(
{ x: pair.data.x.filter((x) => x), y: pair.data.y.filter((y) => y) },
{ x: pair.data.validIndices.map((i) => pair.data.x[i]), y: pair.data.validIndices.map((i) => pair.data.y[i]) },
config.regressionLineOptions.type,
pair.xref,
pair.yref,
Expand Down Expand Up @@ -264,6 +262,7 @@ export function ScatterVis({
config.regressionLineOptions.type,
config.regressionLineOptions.fitOptions,
config.regressionLineOptions.lineStyle,
config.regressionLineOptions.showStats,
subplots,
scatter,
facet,
Expand Down Expand Up @@ -467,7 +466,7 @@ export function ScatterVis({
</div>
) : null}

<div ref={ref} style={{ gridArea: 'plot', overflow: 'hidden' }}>
<div ref={ref} style={{ gridArea: 'plot', overflow: 'hidden', paddingBottom: '0.5rem' }}>
{status === 'success' && layout ? (
<PlotlyComponent
data-testid="ScatterPlotTestId"
Expand Down
1 change: 0 additions & 1 deletion src/vis/scatter/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface IScatterConfig extends BaseVisConfig {
shape: ColumnInfo | null;
dragMode: EScatterSelectSettings;
alphaSliderVal: number;
sizeSliderVal: number;
showLabels: ELabelingOptions;
showLabelLimit?: number;
regressionLineOptions?: IRegressionLineOptions;
Expand Down
3 changes: 1 addition & 2 deletions src/vis/scatter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const defaultConfig: IScatterConfig = {
shape: null,
dragMode: EScatterSelectSettings.RECTANGLE,
alphaSliderVal: 0.5,
sizeSliderVal: 8,
subplots: undefined,
showLabels: ELabelingOptions.NEVER,
showLabelLimit: 50,
Expand Down Expand Up @@ -181,7 +180,7 @@ export function regressionToAnnotation(r: IRegressionResult, precision: number,
xanchor: 'left',
yanchor: 'top',
bgcolor: 'rgba(255, 255, 255, 0.8)',
xshift: 5,
xshift: 10,
yshift: -5,
};
}
2 changes: 0 additions & 2 deletions src/vis/stories/Vis/Scatter/ScatterIris.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Basic.args = {
],
color: null,
facets: null,
sizeSliderVal: 8,
numColorScaleType: ENumericalColorScaleType.SEQUENTIAL,
shape: null,
dragMode: EScatterSelectSettings.RECTANGLE,
Expand Down Expand Up @@ -152,7 +151,6 @@ ControlledSubplots.args = {
},
],
facets: null,
sizeSliderVal: 8,
numColorScaleType: ENumericalColorScaleType.SEQUENTIAL,
shape: null,
dragMode: EScatterSelectSettings.RECTANGLE,
Expand Down

0 comments on commit f67d209

Please sign in to comment.