Skip to content

Commit 229d39a

Browse files
committed
fix: chart is now absolute, so as to no skrew up flex basis
1 parent d335ade commit 229d39a

File tree

4 files changed

+79
-2722
lines changed

4 files changed

+79
-2722
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ d3/index.js
2323
npm-debug.log*
2424
yarn-debug.log*
2525
yarn-error.log*
26-
.history
26+
.history
27+
stats.html

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"titleBar.activeBackground": "#a08600", // change this color!
4+
"titleBar.inactiveBackground": "#a08600", // change this color!
5+
"titleBar.activeForeground": "#ffffff", // change this color!
6+
"titleBar.inactiveForeground": "#ffffff" // change this color!
7+
}
8+
}

src/components/ChartInner.js

+69-69
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import React from "react";
1+
import React from 'react'
22
//
33
import Raf from '../utils/Raf'
4-
import Utils from "../utils/Utils";
5-
import ChartContext from "../utils/ChartContext";
4+
import Utils from '../utils/Utils'
5+
import ChartContext from '../utils/ChartContext'
66

7-
import Rectangle from "../primitives/Rectangle";
7+
import Rectangle from '../primitives/Rectangle'
88

9-
import Voronoi from "./Voronoi";
10-
import Axis from "./Axis";
11-
import Tooltip from "./Tooltip";
12-
import Cursor from "./Cursor";
13-
import Brush from "./Brush";
9+
import Voronoi from './Voronoi'
10+
import Axis from './Axis'
11+
import Tooltip from './Tooltip'
12+
import Cursor from './Cursor'
13+
import Brush from './Brush'
1414

1515
export default React.forwardRef(function ChartInner(
1616
{ className, style = {}, ...rest },
1717
ref
1818
) {
19-
const [chartState] = React.useContext(ChartContext);
19+
const [chartState] = React.useContext(ChartContext)
2020
const [
2121
{
2222
width,
@@ -31,75 +31,75 @@ export default React.forwardRef(function ChartInner(
3131
onClick,
3232
seriesOptions,
3333
getSeriesOrder,
34-
focused
34+
focused,
3535
},
36-
setChartState
37-
] = React.useContext(ChartContext);
36+
setChartState,
37+
] = React.useContext(ChartContext)
3838

39-
const svgRef = React.useRef();
39+
const svgRef = React.useRef()
4040

4141
React.useLayoutEffect(() => {
4242
if (!svgRef.current) {
43-
return;
43+
return
4444
}
45-
const current = svgRef.current.getBoundingClientRect();
45+
const current = svgRef.current.getBoundingClientRect()
4646
if (current.left !== offset.left || current.top !== offset.top) {
4747
setChartState(state => ({
4848
...state,
4949
offset: {
5050
left: current.left,
51-
top: current.top
52-
}
53-
}));
51+
top: current.top,
52+
},
53+
}))
5454
}
55-
});
55+
})
5656

5757
const onMouseLeave = e => {
5858
setChartState(state => ({
5959
...state,
60-
focused: null
61-
}));
60+
focused: null,
61+
}))
6262
setChartState(state => ({
6363
...state,
6464
pointer: {
6565
...state.pointer,
66-
active: false
67-
}
68-
}));
69-
};
66+
active: false,
67+
},
68+
}))
69+
}
7070

71-
const rafRef = React.useRef();
71+
const rafRef = React.useRef()
7272

7373
const onMouseMove = e => {
7474
if (rafRef.current) {
75-
Raf.cancel(rafRef.current);
75+
Raf.cancel(rafRef.current)
7676
}
7777
rafRef.current = Raf(() => {
78-
rafRef.current = null;
79-
const { clientX, clientY } = e;
78+
rafRef.current = null
79+
const { clientX, clientY } = e
8080

8181
setChartState(state => {
82-
const x = clientX - offset.left - gridX;
83-
const y = clientY - offset.top - gridY;
82+
const x = clientX - offset.left - gridX
83+
const y = clientY - offset.top - gridY
8484

8585
const pointer = {
8686
...state.pointer,
8787
active: true,
8888
x,
8989
y,
90-
dragging: state.pointer && state.pointer.down
91-
};
90+
dragging: state.pointer && state.pointer.down,
91+
}
9292
return {
9393
...state,
94-
pointer
95-
};
96-
});
97-
});
98-
};
94+
pointer,
95+
}
96+
})
97+
})
98+
}
9999

100100
const onMouseUp = () => {
101-
document.removeEventListener("mouseup", onMouseUp);
102-
document.removeEventListener("mousemove", onMouseMove);
101+
document.removeEventListener('mouseup', onMouseUp)
102+
document.removeEventListener('mousemove', onMouseMove)
103103

104104
setChartState(state => ({
105105
...state,
@@ -109,43 +109,43 @@ export default React.forwardRef(function ChartInner(
109109
dragging: false,
110110
released: {
111111
x: state.pointer.x,
112-
y: state.pointer.y
113-
}
114-
}
115-
}));
116-
};
112+
y: state.pointer.y,
113+
},
114+
},
115+
}))
116+
}
117117

118118
const onMouseDown = () => {
119-
document.addEventListener("mouseup", onMouseUp);
120-
document.addEventListener("mousemove", onMouseMove);
119+
document.addEventListener('mouseup', onMouseUp)
120+
document.addEventListener('mousemove', onMouseMove)
121121

122122
setChartState(state => ({
123123
...state,
124124
pointer: {
125125
...state.pointer,
126126
sourceX: state.pointer.x,
127127
sourceY: state.pointer.y,
128-
down: true
129-
}
130-
}));
131-
};
128+
down: true,
129+
},
130+
}))
131+
}
132132

133133
// Reverse the stack order for proper z-indexing
134-
const reversedStackData = [...stackData].reverse();
135-
const orderedStackData = getSeriesOrder(reversedStackData);
134+
const reversedStackData = [...stackData].reverse()
135+
const orderedStackData = getSeriesOrder(reversedStackData)
136136

137137
const focusedSeriesIndex = focused
138138
? orderedStackData.findIndex(series => series.id === focused.series.id)
139-
: -1;
139+
: -1
140140

141141
// Bring focused series to the front
142142
const focusOrderedStackData = focused
143143
? [
144144
...orderedStackData.slice(0, focusedSeriesIndex),
145145
...orderedStackData.slice(focusedSeriesIndex + 1),
146-
orderedStackData[focusedSeriesIndex]
146+
orderedStackData[focusedSeriesIndex],
147147
]
148-
: orderedStackData;
148+
: orderedStackData
149149

150150
const stacks = focusOrderedStackData.map(stack => {
151151
return (
@@ -155,27 +155,27 @@ export default React.forwardRef(function ChartInner(
155155
series={stack}
156156
stackData={stackData}
157157
/>
158-
);
159-
});
158+
)
159+
})
160160

161161
return (
162162
<div
163163
ref={ref}
164164
{...rest}
165-
className={`ReactChart ${className || ""}`}
165+
className={`ReactChart ${className || ''}`}
166166
style={{
167167
width,
168168
height,
169-
position: "relative",
170-
...style
169+
position: 'absolute',
170+
...style,
171171
}}
172172
>
173173
<svg
174174
ref={svgRef}
175175
style={{
176176
width,
177177
height,
178-
overflow: "hidden"
178+
overflow: 'hidden',
179179
}}
180180
onMouseEnter={e => e.persist() || onMouseMove(e)}
181181
onMouseMove={e => e.persist() || onMouseMove(e)}
@@ -185,7 +185,7 @@ export default React.forwardRef(function ChartInner(
185185
>
186186
<g
187187
style={{
188-
transform: Utils.translate(gridX, gridY)
188+
transform: Utils.translate(gridX, gridY),
189189
}}
190190
>
191191
<Rectangle
@@ -195,7 +195,7 @@ export default React.forwardRef(function ChartInner(
195195
y1={-gridY}
196196
y2={height - gridY}
197197
style={{
198-
opacity: 0
198+
opacity: 0,
199199
}}
200200
/>
201201
<Voronoi />
@@ -207,7 +207,7 @@ export default React.forwardRef(function ChartInner(
207207
<g
208208
className="Series"
209209
style={{
210-
pointerEvents: "none"
210+
pointerEvents: 'none',
211211
}}
212212
>
213213
{stacks}
@@ -216,7 +216,7 @@ export default React.forwardRef(function ChartInner(
216216
{renderSVG
217217
? renderSVG({
218218
chartState,
219-
setChartState
219+
setChartState,
220220
})
221221
: null}
222222
</svg>
@@ -225,5 +225,5 @@ export default React.forwardRef(function ChartInner(
225225
<Brush />
226226
<Tooltip />
227227
</div>
228-
);
229-
});
228+
)
229+
})

0 commit comments

Comments
 (0)