Skip to content

Commit 09c7415

Browse files
committed
fix: csv data can be loaded
1 parent 23d4eee commit 09c7415

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

src/components/ReactTimeSeries/ReactTimeSeries.stories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ export const TimeDataFromCSV = () => {
141141
return (
142142
<ReactTimeSeries
143143
interface={{
144+
timeFormat: "dates",
144145
durationLabels: ["duration1", "duration2"],
145146
timestampLabels: ["ts1", "ts2"],
146147
enabledTools: ["create-durations"],
148+
graphs: [{ keyName: "high" }, { keyName: "low" }],
147149
}}
148150
sample={sample}
149151
onModifySample={setSample}

src/components/ReactTimeSeries/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export const ReactTimeSeriesWithoutContext = ({
5959
if (sampleTimeData) return fixTimeData(sampleTimeData, graphs)
6060
if (audioUrl) return fixTimeData(await fetchAudioData(audioUrl), graphs)
6161
if (csvUrl) return fixTimeData(await fetchCSVData(csvUrl), graphs)
62-
return []
62+
throw new Error(
63+
`No timeData, no audioUrl, no csvUrl, no time data provided.`
64+
)
6365
} catch (e) {
6466
setError(e)
6567
return []

src/utils/fix-time-data.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default (timeData, graphs) => {
2727
const v = sample[graph.keyName]
2828
if (v !== undefined && v !== null && isNaN(v))
2929
throw new Error(`Bad value for "${graph.keyName}": "${v}"`)
30+
if (typeof v === "string") {
31+
sample[graph.keyName] = parseFloat(v)
32+
}
3033
pointsDefined++
3134
}
3235

src/utils/init-top-level-matrix.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export default ({ curveGroups, width }) => {
66
const allTimes = curveGroups
77
.flatMap((curveGroup) => curveGroup)
88
.flatMap((curve) => curve.data.map(([t]) => t))
9+
10+
if (allTimes.length === 0) return mat
11+
912
const minT = Math.min(...allTimes)
1013
const maxT = Math.max(...allTimes)
1114

0 commit comments

Comments
 (0)