Skip to content

Commit

Permalink
Cache legend item text rect - #730
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki0812 committed Nov 21, 2014
1 parent a788840 commit 1c35022
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 9 additions & 1 deletion c3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,7 @@
.style('opacity', 0)
.style('visibility', 'hidden');
};
var legendItemTextBox = {};
c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
var $$ = this, config = $$.config;
var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect;
Expand All @@ -3776,9 +3777,16 @@
withTransition = getOption(options, "withTransition", true);
withTransitionForTransform = getOption(options, "withTransitionForTransform", true);

function getTextBox(textElement, id) {
if (!legendItemTextBox[id]) {
legendItemTextBox[id] = $$.getTextRect(textElement.textContent, CLASS.legendItem);
}
return legendItemTextBox[id];
}

function updatePositions(textElement, id, index) {
var reset = index === 0, isLast = index === targetIds.length - 1,
box = $$.getTextRect(textElement.textContent, CLASS.legendItem),
box = getTextBox(textElement, id),
itemWidth = box.width + tileWidth + (isLast && !($$.isLegendRight || $$.isLegendInset) ? 0 : paddingRight),
itemHeight = box.height + paddingTop,
itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth,
Expand Down
Loading

0 comments on commit 1c35022

Please sign in to comment.