Skip to content

Commit

Permalink
plotter: Use special drawings for single-value and no-value cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Feb 24, 2025
1 parent 9d14e43 commit 4322243
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/components/widgets/Plotter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,33 @@ const renderCanvas = (): void => {
// Draw the graph
ctx.beginPath()
ctx.moveTo(0, canvasHeight / 2)
valuesHistory.forEach((sample, index) => {
const x = index * (canvasWidth / valuesHistory.length)
const y = canvasHeight - ((sample - minY) / (maxY - minY)) * canvasHeight
ctx.lineTo(x, y)
})
ctx.setLineDash([])
if (valuesHistory.length === 0) {
// Draw an open circle in the middle of the canvas indicating no value
ctx.beginPath()
ctx.arc(canvasWidth / 2, canvasHeight / 2, 5, 0, 2 * Math.PI)
ctx.stroke()
} else if (valuesHistory.length === 1) {
// Draw a filled circle in the middle of the canvas with a small dash line to the right indicating a single value
ctx.fillStyle = widget.value.options.lineColor
ctx.beginPath()
ctx.arc(canvasWidth / 2, canvasHeight / 2, 5, 0, 2 * Math.PI)
ctx.fill()
ctx.beginPath()
ctx.setLineDash([5, 5])
ctx.moveTo(canvasWidth / 2, canvasHeight / 2)
ctx.lineTo(canvasWidth / 2 + 50, canvasHeight / 2)
ctx.stroke()
} else {
ctx.setLineDash([])
valuesHistory.forEach((sample, index) => {
const x = index * (canvasWidth / valuesHistory.length)
const y = canvasHeight - ((sample - minY) / (maxY - minY)) * canvasHeight
ctx.lineTo(x, y)
})
}
ctx.stroke()
// Setup text rendering
Expand Down

0 comments on commit 4322243

Please sign in to comment.