leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.51k stars 371 forks source link

Uneven gap in the bar chart #815

Closed 17839359913 closed 1 year ago

17839359913 commented 1 year ago
image

In some cases, the gap of the bar chart is not uniform, with an error of 0.5px。 Is this a known problem?

leeoniya commented 1 year ago

this is because uPlot generally prefers crisp edges, rounded to pixel boundaries.

you can turn this off globally or on a per-series basis:

https://github.com/leeoniya/uPlot/blob/1697833479862f8ae0a446b880fa39237a793fc9/dist/uPlot.d.ts#L369-L370

https://github.com/leeoniya/uPlot/blob/1697833479862f8ae0a446b880fa39237a793fc9/dist/uPlot.d.ts#L862-L863

for series with hundreds or thousands of datapoints, turning this off is not a good idea because the rendering code uses is-same-pixel comparisons to improve drawing performance. but in the case of bars with only a few dozen points, it should not have any measurable effect.

17839359913 commented 1 year ago

Thank you very much. May I ask for your advice? Can you tell me the reason for the ambiguity?

leeoniya commented 1 year ago

Can you tell me the reason for the ambiguity?

i dont understand your question. what is ambiguous here?

17839359913 commented 1 year ago

I have a new problem where the first and last points are always rendered in half. Is there any way to solve this problem?

image
leeoniya commented 1 year ago

you can expand the time range a little. uPlot will not expand the time range automatically.

https://jsfiddle.net/0bvks7cw/1/

let data = [
  [0, 1, 2, 3, 4, 5, 6],
  [1, 2, 3, 4, 3, 2, 1],
];

const opts = {
  width: 800,
  height: 400,
  scales: {
    x: {
      time: false,
      range: (u, from, to) => {
        let pad = (to - from) * 0.05;
        return [from - pad, to + pad];
      },
    },
  },
  series: [
    {},
    {
      stroke: "red",
      fill: "#ff000020",
      paths: uPlot.paths.bars(),
    },
  ],
};

let u = new uPlot(opts, data, document.body);
17839359913 commented 1 year ago

Thank you very much.

17839359913 commented 1 year ago

I have a new question. If you move the mouse quickly, hook.setSeries will execute very frequently, and the transparency of the series will change frequently, feeling very jittery. Is there any way to add interception? Just like useDebounce

https://user-images.githubusercontent.com/22956606/230562637-16499639-660a-4cf1-b13a-19034834853a.mov

leeoniya commented 1 year ago

no, not currently: https://github.com/leeoniya/uPlot/issues/787

17839359913 commented 1 year ago

But this is really very performance intensive. If there are 100 series, it is very important to me

leeoniya commented 1 year ago

what solution do you suggest?