Skip to content

Commit cdf5bce

Browse files
committed
fix: fix y axis direction, create csv story
1 parent a41df0c commit cdf5bce

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

src/components/ControllableWave/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ export const ControllableWave = ({
2626
const minY = Math.min(...curves[0].data.map(([, y]) => y))
2727

2828
return mat
29+
.scale(1, -1)
2930
.scale(1, height)
3031
.scale(1, 1 / (maxY - minY))
31-
.translate(0, -minY)
32+
.translate(0, -maxY)
3233
})
3334

3435
matrix = matrix

src/components/ReactTimeSeries/ReactTimeSeries.stories.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const ReallySimple = () => {
5252
sample={{
5353
timeData: [
5454
{ time: 0, value: 0 },
55-
{ time: 500, value: 500 },
55+
{ time: 500, value: 750 },
5656
{ time: 1000, value: 1000 },
5757
],
5858
}}
@@ -132,3 +132,21 @@ export const CreateDurationsOnly = () => {
132132
/>
133133
)
134134
}
135+
136+
export const TimeDataFromCSV = () => {
137+
const [sample, setSample] = useState({
138+
csvUrl:
139+
"https://gist.githubusercontent.com/philaturner/644b3e8bd17641766d90f38d475edcc6/raw/a6c35e97a89eda49098def90fe2e750ceb898f79/tesla.csv",
140+
})
141+
return (
142+
<ReactTimeSeries
143+
interface={{
144+
durationLabels: ["duration1", "duration2"],
145+
timestampLabels: ["ts1", "ts2"],
146+
enabledTools: ["create-durations"],
147+
}}
148+
sample={sample}
149+
onModifySample={setSample}
150+
/>
151+
)
152+
}

src/components/Wave/index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ const reduceForVisibleDuration = (data, startTime, visibleDuration, width) => {
3131
if (data[i][0] - points[points.length - 1][0] > minDistance) {
3232
// points.push(data[i])
3333
const timeSinceLastPoint = data[i][0] - points[points.length - 1][0]
34-
35-
points.push([
36-
data[i][0] - timeSinceLastPoint / 2,
37-
Math.max(
38-
...data.slice(lastAddedPointIndex + 1, i + 1).map(([, v]) => v)
39-
),
40-
])
41-
42-
points.push([
43-
data[i][0],
44-
Math.min(
45-
...data.slice(lastAddedPointIndex + 1, i + 1).map(([, v]) => v)
46-
),
47-
])
34+
if (i - lastAddedPointIndex === 1) {
35+
points.push(data[i])
36+
} else {
37+
points.push([
38+
data[i][0] - timeSinceLastPoint / 2,
39+
Math.max(
40+
...data.slice(lastAddedPointIndex + 1, i + 1).map(([, v]) => v)
41+
),
42+
])
43+
44+
points.push([
45+
data[i][0],
46+
Math.min(
47+
...data.slice(lastAddedPointIndex + 1, i + 1).map(([, v]) => v)
48+
),
49+
])
50+
}
4851

4952
lastAddedPointIndex = i
5053
}

0 commit comments

Comments
 (0)