Skip to content

Commit

Permalink
fix(legend): Fix resizing when legend template is used (#706)
Browse files Browse the repository at this point in the history
Scale & sizes update should peform after template updates

Fix #705
Close #706
  • Loading branch information
netil committed Dec 17, 2018
1 parent 517ae1e commit 87294dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
11 changes: 11 additions & 0 deletions spec/internals/legend-spec.js
Expand Up @@ -367,6 +367,17 @@ describe("LEGEND", () => {

expect(items.size()).to.be.equal(1);
});

it("check for resizing", () => {
const newSize = {width: 1200, height: 1400};

chart.resize(newSize);

expect(chart.internal.getCurrentWidth()).to.be.equal(newSize.width);
expect(chart.internal.getCurrentHeight()).to.be.equal(newSize.height);

chart.destroy();
});
});

describe("when using custom points", () => {
Expand Down
31 changes: 17 additions & 14 deletions src/internals/legend.js
Expand Up @@ -46,19 +46,28 @@ extend(ChartInternal.prototype, {
updateLegend(targetIds, options, transitions) {
const $$ = this;
const config = $$.config;
const optionz = options || {
withTransform: false,
withTransitionForTransform: false,
withTransition: false
};

if (config.legend_contents_bindto && config.legend_contents_template) {
$$.updateLegendTemplate();
} else {
$$.updateLegendElement(
targetIds || $$.mapToIds($$.data.targets),
options || {
withTransform: false,
withTransitionForTransform: false,
withTransition: false
}, transitions
optionz,
transitions
);
}

// Update size and scale
$$.updateSizes();
$$.updateScales(!optionz.withTransform);
$$.updateSvgSize();

$$.legendHasRendered = true;
},

/**
Expand Down Expand Up @@ -392,9 +401,9 @@ extend(ChartInternal.prototype, {
// Skip elements when their name is set to null
const targetIdz = targetIds
.filter(id => !isDefined(config.data_names[id]) || config.data_names[id] !== null);
const optionz = options || {};
const withTransition = getOption(optionz, "withTransition", true);
const withTransitionForTransform = getOption(optionz, "withTransitionForTransform", true);

const withTransition = getOption(options, "withTransition", true);
const withTransitionForTransform = getOption(options, "withTransitionForTransform", true);

const getTextBox = function(textElement, id) {
if (!$$.legendItemTextBox[id]) {
Expand Down Expand Up @@ -666,13 +675,7 @@ extend(ChartInternal.prototype, {
$$.updateLegendItemHeight(maxHeight);
$$.updateLegendStep(step);

// Update size and scale
$$.updateSizes();
$$.updateScales(!withTransition);
$$.updateSvgSize();

// Update g positions
$$.transformAll(withTransitionForTransform, transitions);
$$.legendHasRendered = true;
}
});

0 comments on commit 87294dd

Please sign in to comment.