Skip to content

Commit

Permalink
Use a single cached value instead of growing indefinitely
Browse files Browse the repository at this point in the history
Pro: smaller, simpler
Con: slower on graphs where you toggle styles

Ref: Node label flickering when animating font-size #3270
  • Loading branch information
maxkfranz committed Nov 11, 2024
1 parent 40fec5a commit f8bb923
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/extensions/renderer/base/coord-ele-math/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,11 @@ BRp.calculateLabelDimensions = function( ele, text ){

var document = containerWindow.document;

let cacheKey = util.hashString( text, ele._private.labelDimsKey );
let cacheKey = util.hashString(text, ele._private.labelDimsKey);
let cache = r.labelDimCache || (r.labelDimCache = { key: null, value: null });

let cache = r.labelDimCache || (r.labelDimCache = []);

let existingVal = cache[ cacheKey ];

if( existingVal != null ){
return existingVal;
if (cache.key === cacheKey) {
return cache.value;
}

let padding = 0; // add padding around text dims, as the measurement isn't that accurate
Expand Down Expand Up @@ -522,10 +519,13 @@ BRp.calculateLabelDimensions = function( ele, text ){
width += padding;
height += padding;

return ( cache[ cacheKey ] = {
cache.key = cacheKey;
cache.value = {
width,
height
} );
};

return cache.value;
};


Expand Down

0 comments on commit f8bb923

Please sign in to comment.