Skip to content

Commit 09151ab

Browse files
committed
minor plot fixes, trial fixing refresh
1 parent dac70bc commit 09151ab

7 files changed

Lines changed: 270 additions & 77 deletions

File tree

src/components/app.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import SurveyEntry from '../model/surveyEntry'
1515
import RawDataTable from './rawDataTable'
1616
import ConsideredDataTable from './consideredDataTable'
1717
import { uiStore } from '../stores/uiStore'
18+
import { AbstractCsvRowMapper } from '../mapper/AbstractCsvRowMapper'
1819

1920
interface AppState {
2021
components: number[],
@@ -31,8 +32,16 @@ class App extends React.Component<Record<string, unknown>, AppState> {
3132
components: [0, 1],
3233
tabIndex: 0
3334
}
34-
// Store must be created only once.
3535
SurveyEntry.entryStore = entryStore
36+
const urlParams = new URLSearchParams(window.location.search)
37+
const settingsParam = urlParams.get('settings')
38+
if (settingsParam) {
39+
try {
40+
controlStore.pendingState = JSON.parse(decodeURIComponent(settingsParam))
41+
} catch (e) {
42+
console.error('Failed to parse settings from URL', e)
43+
}
44+
}
3645
}
3746

3847
render(): JSX.Element {

src/components/barplot.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import Plot from 'react-plotly.js'
3+
import { Data, Layout } from 'plotly.js'
34
import { inject, observer } from 'mobx-react'
45
import { injectClause, StoreProps } from '../stores/storeHelper'
56

@@ -10,7 +11,7 @@ class BarPlot extends React.Component<StoreProps> {
1011
<div style={{position: 'absolute', top: 0, bottom: 0, left:0, right: 0, overflow: 'auto'}}>
1112
<Plot
1213
data={this.data}
13-
layout={{barmode: 'group', showlegend: false}}
14+
layout={this.layout}
1415
style={{width: '100%', height: '100%'}}
1516
/>
1617
</div>
@@ -45,6 +46,15 @@ class BarPlot extends React.Component<StoreProps> {
4546
];
4647
return traces;
4748
}
49+
50+
get layout(): Partial<Layout> {
51+
return {
52+
barmode: 'group',
53+
showlegend: true,
54+
paper_bgcolor: '#FF000000',
55+
plot_bgcolor: '#FF000000'
56+
}
57+
}
4858
}
4959

5060
export default inject(...injectClause)(observer(BarPlot))

src/components/boxplot.tsx

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
import React from 'react'
2-
import Plot from 'react-plotly.js'
3-
import { Data, Layout } from 'plotly.js'
1+
import React, { MutableRefObject, useRef } from 'react'
2+
import Plot, { Figure } from 'react-plotly.js'
3+
import { Data, Layout, PlotData, PlotlyHTMLElement } from 'plotly.js'
44
import { inject, observer } from 'mobx-react'
55
import SurveyEntry from '../model/surveyEntry'
66
import { injectClause, StoreProps } from '../stores/storeHelper'
7-
7+
// Define the shape of the figure argument passed by react-plotly.js
8+
/*interface PlotlyFigure {
9+
data: PlotData[];
10+
layout: Partial<Layout>;
11+
frames: any[] | null;
12+
}*/
13+
814
class BoxPlot extends React.Component<StoreProps> {
915

16+
1017
defaultBoxConfig: Partial<Data> = {
1118
type: 'box',
1219
boxmean: 'sd',
1320
// boxpoints: 'all',
1421
// jitter: 0.3,
1522
// pointpos: -1.8
1623
}
24+
// Create a reference to store the plot instance
25+
//plotRef: MutableRefObject<HTMLElement | null> = useRef(null);
26+
1727

1828
render(): JSX.Element {
1929
/*
@@ -32,6 +42,52 @@ class BoxPlot extends React.Component<StoreProps> {
3242
)
3343
}
3444

45+
/*
46+
render(): JSX.Element {
47+
return (
48+
<div style={{position: 'absolute', top: 0, bottom: 0, left:0, right: 0, overflow: 'auto'}}>
49+
<Plot
50+
data={this.data}
51+
layout={this.layout}
52+
style={{width: '100%', height: '100%'}}
53+
// Store reference and trigger hover when first loaded
54+
onInitialized={this.initializ}
55+
// Re-trigger hover if the plot layout updates or resizes
56+
onUpdate={this.update}
57+
// Re-trigger hover when user moves mouse away
58+
onUnhover={this.unhover}
59+
60+
/>
61+
</div>
62+
)
63+
}
64+
65+
pinBoxHover(plotElement: HTMLElement | null): void {
66+
// Cast window or element to access Fx API safely in TypeScript
67+
const plotlyModule = (window as any).Plotly || (plotElement as any)?.Plotly;
68+
69+
if (plotElement && plotlyModule) {
70+
plotlyModule.Fx.hover(plotElement, [
71+
{ curveNumber: 0, pointNumber: 0 }
72+
]);
73+
}
74+
75+
};
76+
77+
initializ(figure: Readonly<Figure>, graphDiv: Readonly<HTMLElement>): void {
78+
this.plotRef.current = graphDiv;
79+
this.pinBoxHover(graphDiv);
80+
}
81+
82+
update(figure: Readonly<Figure>): void {
83+
this.pinBoxHover(this.plotRef.current);
84+
}
85+
86+
unhover(): void {
87+
this.pinBoxHover(this.plotRef.current);
88+
}*/
89+
90+
3591
private get data(): Data[] { // TODO: Plotty Data
3692
const resultList = this.props.uiStore!.filteredData
3793
const selectedYearStr = this.props.controlStore!.controlState.selectedYear
@@ -47,7 +103,7 @@ class BoxPlot extends React.Component<StoreProps> {
47103
const trace: Data = {
48104
type: 'box',
49105
boxmean: 'sd',
50-
name: 'Year' + selectedYearStr,
106+
name: 'Year ' + selectedYearStr,
51107
y: yearData.map((entry: SurveyEntry) => entry.salary),
52108
};
53109
return [trace];
@@ -57,10 +113,14 @@ class BoxPlot extends React.Component<StoreProps> {
57113
return {
58114
autosize: true,
59115
showlegend: false,
116+
// 'x' mode forces plotly to show the summary statistics for the column on that X coordinate
117+
// hovermode: 'x',
118+
//hovermode: 'closest',
60119
yaxis: {fixedrange: true},
61120
xaxis : {fixedrange: true},
62121
paper_bgcolor: '#FF000000',
63-
plot_bgcolor: '#FF000000'
122+
plot_bgcolor: '#FF000000',
123+
// hoverdistance: -1
64124
}
65125
}
66126
}

0 commit comments

Comments
 (0)