plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.88k stars 1.85k forks source link

Plotly js relayout not working #6497

Closed tanujdrivetech closed 2 months ago

tanujdrivetech commented 1 year ago

Plotly js relayout not working for last element inside loop specially for annotations.

code for handle annotations:-

const handleAnnotation = (data, graphId) => { var divid = graphRef.current.el; var point = data.points[0], newAnnotation = { x: point.xaxis.d2l(point.x), y: point.yaxis.d2l(point.y), arrowhead: 6, ax: 0, ay: -80, xref: point.data.xaxis ? point.data.xaxis : "x", yref: point.data.yaxis ? point.data.yaxis : "y", bgcolor: "rgba(255, 255, 255, 0.9)", font: { size: 18, color: "black" }, bordercolor: point.fullData && point.fullData.line ? point.fullData.line.color : !point.fullData.line ? point["marker.color"] : "blue", arrowcolor: point.fullData && point.fullData.line ? point.fullData.line.color : !point.fullData.line ? point["marker.color"] : "red", borderwidth: 3, borderpad: 4, name: point.data.key, text: "Add annotation here....", arrowwidth: 3, hovertext: "clear text to delete annotation", }, newIndex = (divid.layout.annotations || []).length; // delete instead if clicked twice if (newIndex) { var foundCopy = false; divid.layout.annotations.forEach(function (ann, sameIndex) { if (ann.text === newAnnotation.text) { Plotly.relayout(graphId, "annotations[" + sameIndex + "]", "remove"); foundCopy = true; } else if (ann.text === "") { Plotly.relayout(graphId, "annotations[" + sameIndex + "]", "remove"); foundCopy = true; } }); if (foundCopy) return; } Plotly.relayout(graphId, "annotations[" + newIndex + "]", newAnnotation); };

gvwilson commented 2 months ago

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson