Skip to content

Commit

Permalink
Merge pull request #5579 from plotly/legend-draw-refactor
Browse files Browse the repository at this point in the history
Refactor legend draw to make input/output and optional arguments clear
  • Loading branch information
archmoj authored Apr 6, 2021
2 parents ac6fef5 + ab23397 commit dbf9364
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 157 deletions.
13 changes: 7 additions & 6 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,10 @@ function createHoverText(hoverData, opts, gd) {
};
var mockLayoutOut = {};
legendSupplyDefaults(mockLayoutIn, mockLayoutOut, gd._fullData);
var legendOpts = mockLayoutOut.legend;
var mockLegend = mockLayoutOut.legend;

// prepare items for the legend
legendOpts.entries = [];
mockLegend.entries = [];
for(var j = 0; j < hoverData.length; j++) {
var texts = getHoverLabelText(hoverData[j], true, hovermode, fullLayout, t0);
var text = texts[0];
Expand All @@ -1039,13 +1039,14 @@ function createHoverText(hoverData, opts, gd) {
}
pt._distinct = true;

legendOpts.entries.push([pt]);
mockLegend.entries.push([pt]);
}
legendOpts.entries.sort(function(a, b) { return a[0].trace.index - b[0].trace.index;});
legendOpts.layer = container;
mockLegend.entries.sort(function(a, b) { return a[0].trace.index - b[0].trace.index;});
mockLegend.layer = container;

// Draw unified hover label
legendDraw(gd, legendOpts);
mockLegend._inHover = true;
legendDraw(gd, mockLegend);

// Position the hover
var ly = Lib.mean(hoverData.map(function(c) {return (c.y0 + c.y1) / 2;}));
Expand Down
Loading

0 comments on commit dbf9364

Please sign in to comment.