Skip to content

Commit

Permalink
fix(legend): Fix resize for arc (#707)
Browse files Browse the repository at this point in the history
Correct arcs transform when template legend is used

Ref #705
Close #707
  • Loading branch information
netil committed Dec 17, 2018
1 parent 87294dd commit 89a3ece
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
21 changes: 21 additions & 0 deletions spec/internals/legend-spec.js
Expand Up @@ -378,6 +378,27 @@ describe("LEGEND", () => {

chart.destroy();
});

it("set options data.type='pie'", () => {
args.data.type = "pie";
});

it("check for resizing for pie type", () => {
const newSize = {width: 300, height: 300};
const transform1 = chart.$.arc.attr("transform").split(",").map(util.parseNum);

chart.resize(newSize);

const transform2 = chart.$.arc.attr("transform").split(",").map(util.parseNum);

expect(transform1).to.not.be.deep.equal(transform2);

transform1.forEach((v, i) => {
expect(v).to.be.above(transform2[i]);
});

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

describe("when using custom points", () => {
Expand Down
3 changes: 1 addition & 2 deletions src/internals/ChartInternal.js
Expand Up @@ -1051,8 +1051,7 @@ export default class ChartInternal {
$$.config.subchart_show &&
$$.transformContext(withTransition, transitions);

$$.legend &&
$$.transformLegend(withTransition);
$$.legend && $$.transformLegend(withTransition);
}

updateSvgSize() {
Expand Down
25 changes: 13 additions & 12 deletions src/internals/legend.js
Expand Up @@ -38,9 +38,9 @@ extend(ChartInternal.prototype, {

/**
* Update legend element
* @param targetIds
* @param options
* @param transitions
* @param {Array} targetIds ID's of target
* @param {Object} options withTransform : Whether to use the transform property / withTransitionForTransform: Whether transition is used when using the transform property / withTransition : whether or not to transition.
* @param {Object} transitions Return value of the generateTransitions
* @private
*/
updateLegend(targetIds, options, transitions) {
Expand All @@ -52,6 +52,9 @@ extend(ChartInternal.prototype, {
withTransition: false
};

optionz.withTransition = getOption(optionz, "withTransition", true);
optionz.withTransitionForTransform = getOption(optionz, "withTransitionForTransform", true);

if (config.legend_contents_bindto && config.legend_contents_template) {
$$.updateLegendTemplate();
} else {
Expand All @@ -64,9 +67,12 @@ extend(ChartInternal.prototype, {

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

// Update g positions
$$.transformAll(optionz.withTransitionForTransform, transitions);

$$.legendHasRendered = true;
},

Expand Down Expand Up @@ -372,12 +378,11 @@ extend(ChartInternal.prototype, {

/**
* Update the legend
* @private
* @param {Array} targetIds ID's of target
* @param {Object} options withTransform : Whether to use the transform property / withTransitionForTransform: Whether transition is used when using the transform property / withTransition : whether or not to transition.
* @param {Object} transitions Return value of the generateTransitions
* @private
*/
updateLegendElement(targetIds, options, transitions) {
updateLegendElement(targetIds, options) {
const $$ = this;
const config = $$.config;
const paddingTop = 4;
Expand All @@ -402,8 +407,7 @@ extend(ChartInternal.prototype, {
const targetIdz = targetIds
.filter(id => !isDefined(config.data_names[id]) || config.data_names[id] !== null);

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

const getTextBox = function(textElement, id) {
if (!$$.legendItemTextBox[id]) {
Expand Down Expand Up @@ -674,8 +678,5 @@ extend(ChartInternal.prototype, {
$$.updateLegendItemWidth(maxWidth);
$$.updateLegendItemHeight(maxHeight);
$$.updateLegendStep(step);

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

0 comments on commit 89a3ece

Please sign in to comment.