Skip to content

missing points in plot when surrounded by null values #1042

Open
@nicolaszuts

Description

@nicolaszuts

Hi,

I wanted to share an edge case that we've encountered when dealing with null data points. If a non-null data point is surrounded by null values, and if we haven't overriden the default options, then we risk encountering a situation where a point does not show up in the plot unless hovered. I've attached screenshots and a demo for your reference:

Image
Image

Demo: https://codepen.io/tempac0345/pen/wvVOEPq

As you can see, the data does have a point in index 2 but it does not show up in the first image. We've managed to fix this on our side with the following series point options:

const seriesPointsFilter = (
  u,
  sIdx,
  show,
)=> {
  const vals = u.data[sIdx];

  // respect when default uplot behaviour sets show to true
  if (seriesPointsShow(u, sIdx)) {
    return Array.from(vals.keys());
  }

  const indices: number[] = [];

  for (let i = 0; i < vals.length; i++) {
    if (vals[i] === null) {
      continue;
    }

    const prevNull =
      i === 0 || vals[i - 1] === null
    const nextNull =
      i === vals.length - 1 ||
      vals[i + 1] === null

    if (prevNull && nextNull) indices.push(i);
  }

  return indices;
};

 points: {
            show: true,
            filter: seriesPointsFilter,
          },

As you can see, we use the series point filter option to maintain the default "show" behaviour where relevant whilst also forcing the non-null points surrounded by null values to show up in the chart. It's not ideal for every use case but it works well for us.

My opinion is that hiding those points feels like unexpected behavior. We use uplot for dynamic data and so this issue went unnoticed for a few days. In our case, those data points are of equal importance to the rest of the data. It feels to me like it should be part of the default behaviour so I thought it best to share this with you just in case you agreed. If you disagree, feel free to close the issue.

Thanks as always!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions