8000 Misc perf improvements by alexcjohnson · Pull Request #1772 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clear bbox cache to fix bar test
  • Loading branch information
alexcjohnson committed Jun 9, 2017
commit a511bd2da8eae39eab8da8b031359b74bfd7bcc0
8 changes: 4 additions & 4 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,15 @@ drawing.makeTester = function() {
// in a reference frame where it isn't translated and its anchor
// point is at (0,0)
// always returns a copy of the bbox, so the caller can modify it safely
var savedBBoxes = {};
drawing.savedBBoxes = {};
var savedBBoxesCount = 0;
var maxSavedBBoxes = 10000;

drawing.bBox = function(node) {
// cache elements we've already measured so we don't have to
// remeasure the same thing many times
var hash = nodeHash(node);
var out = savedBBoxes[hash];
var out = drawing.savedBBoxes[hash];
if(out) return Lib.extendFlat({}, out);

var tester = drawing.tester.node();
Expand Down Expand Up @@ -654,12 +654,12 @@ drawing.bBox = function(node) {
// or a long session could overload on memory
// by saving boxes for long-gone elements
if(savedBBoxesCount >= maxSavedBBoxes) {
savedBBoxes = {};
drawing.savedBBoxes = {};
maxSavedBBoxes = 0;
}

// cache this bbox
savedBBoxes[hash] = bb;
drawing.savedBBoxes[hash] = bb;
savedBBoxesCount++;

return Lib.extendFlat({}, bb);
Expand Down
11 changes: 11 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,17 @@ describe('A bar plot', function() {
assertTextIsInsidePath(text20, path20); // inside
assertTextIsBelowPath(text30, path30); // outside

// clear bounding box cache - somehow when you cache
// text size too early sometimes it changes later...
// we've had this issue before, where we've had to
// redraw annotations to get final sizes, I wish we
// could get some signal that fonts are really ready
// and not start drawing until then (or invalidate
// the bbox cache when that happens?)
// without this change, we get an error at
// assertTextIsInsidePath(text30, path30);
Drawing.savedBBoxes = {};

return Plotly.restyle(gd, 'textposition', 'inside');
}).then(function() {
var cd = gd.calcdata;
Expand Down
0