plotly / plotly/plotly.js

Error when providing axis tickformat, but dataset is empty

Open
#7,169 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

I could not find this anywhere in reported/open/closed problems, so here goes.
I'm dynamically fetching my dataset for plotly - and sometimes there is no data - a normal condition for my app.
When providing a timestamp-like xaxis tickformat, an error will occur when the dataset is empty.

  Plotly.newPlot(this.chartTarget.id, {
    data: [
      { name: "Spot", type: "scatter", mode: 'lines', x: [], y: [], line: {color: 'black'} },
    ],
    layout: {
      title: "Blah",
      hovermode: "closest",
      hoverlabel: { bgcolor: "#FFF" },
      legend: { orientation: 'h', y: -0.3 },
      xaxis: { tickformat: "%H:%M", title: {text: "Time", automargin: true, standoff: 0}, zeroline: false },
      yaxis: { title: "YAxis" }
    },
    config: { responsive: true }
  });

When the dataset is empty alike above (and only when empty), a JS error will be thrown with a trace that looks like:

console.trace() WARN: encountered bad format: "%H:%M" plotly-finance.js:27425:18
warn plotly-finance.js:27425
warnBadFormat plotly-finance.js:25902
numberFormat plotly-finance.js:50110
numFormat plotly-finance.js:40235
formatLinear plotly-finance.js:40138
tickText plotly-finance.js:39918
setTickLabel plotly-finance.js:39477
calcTicks plotly-finance.js:39509
drawOne plotly-finance.js:40613
draw plotly-finance.js:40541
syncOrAsync plotly-finance.js:26272
draw plotly-finance.js:40534
drawAxes plotly-finance.js:31315
syncOrAsync plotly-finance.js:26272
_doPlot plotly-finance.js:31340
newPlot plotly-finance.js:31501

It seems like the format handler should be able to detect this situation and avoid the error when there's actually nothing to format in the first place.

Thanks for consideration and hopeful for a resolution within plotly itself for this potentially-expected condition.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied Plotly.newPlot call with empty x and y arrays and xaxis tickformat "%H:%M". Start from the newPlot call and the format-related stack entries in plotly-finance.js, then confirm that an empty dataset no longer produces the bad-format error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.