plotly / plotly/plotly.js

Type definition error: Type Date is not assignable to type `Annotations.x`

Open
#6,868 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi,

I'm getting typescript error when trying to set Date object for Annotations.x in axis type is date chart.
Note that if you ignore this error and run the program, the position of the X in the annotation will be as expected.

Environments

  • "plotly.js":"2.28.0"
  • "@types/plotly.js":"2.12.32"

Declared here

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/plotly.js/index.d.ts#L2006-L2014

Document

https://plotly.com/javascript/reference/layout/annotations/#layout-annotations-items-annotation-x

x
Parent: layout.annotations[]
Type: number or categorical coordinate string
Sets the annotation's x position. If the axis type is "log", then you must take the log of your desired range. If the axis type is "date", it should be date strings, like date data, though Date objects and unix milliseconds will be accepted and converted to strings. If the axis type is "category", it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears.

SS

スクリーンショット 2024-01-26 17 58 06

Thank you for the support!

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

Start with the Annotations.x declaration in types/plotly.js/index.d.ts at the referenced lines, then compare its type with the Plotly annotation documentation. Confirm that a Date value for a date axis is accepted by the type definition, and validate the result with a minimal TypeScript usage matching the reported case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.