Skip to content

Commit

Permalink
interpolate csv data
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Jul 6, 2024
1 parent e7e09a1 commit 2a2d170
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/Plotly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ export default {
index = indexes[series]
x = data[series].x[index]
}
line.push(data[series].y[index])
const y = data[series].y[index]
const prevX = data[series].x[index - 1]
const prevY = data[series].y[index - 1]
const interpolatedY = this.interpolateY(prevY, y, prevX, x, currentTime)
line.push(interpolatedY)
}
csv.push(line)
currentTime = currentTime + interval
Expand All @@ -318,6 +322,16 @@ export default {
}
}
},
interpolateY (y1, y2, x1, x2, x) {
const dx = x2 - x1
if (dx <= 0) {
throw new Error('x2 must be greater than x1')
}
const dy = y2 - y1
const slope = dy / dx
const interpolatedY = y1 + slope * dx
return interpolatedY
},
resize () {
Plotly.Plots.resize(this.gd)
},
Expand Down

0 comments on commit 2a2d170

Please sign in to comment.