uPlot icon indicating copy to clipboard operation
uPlot copied to clipboard

Can scatter plot achieve the shape of scatter points?

Open haibins opened this issue 2 years ago • 1 comments

I am trying to implement scatter plots with shapes other than circles, such as rhombuses, hexagons, etc., and connect the points with lines. Is there any such demo? This feature is important because the data I use has a lot of duplicate x data , thanks

haibins avatar Jan 16 '24 09:01 haibins

i think it would be cool to add these to the scatter demo. you'd have to make a new pathBuilder that accepts a shape string as an option or something. internally, a diamond can be drawn like this:

let halfDiagMult = Math.sqrt(2) / 2;

function drawMark(ctx, x, y, size = 10) {
  let halfDiag = size * halfDiagMult;

  ctx.beginPath();
  ctx.moveTo(x - halfDiag, y);
  ctx.lineTo(x, y - halfDiag);
  ctx.lineTo(x + halfDiag, y);
  ctx.lineTo(x, y + halfDiag);
  ctx.fill();
}

leeoniya avatar Jan 16 '24 16:01 leeoniya