Skip to content

Commit

Permalink
fix(legend): Fix error for color.threshold option
Browse files Browse the repository at this point in the history
Prevent setting legend color when chart has no legend

Fix naver#1604
Close naver#1611
  • Loading branch information
alanhamlett authored and netil committed Aug 18, 2020
1 parent 49dd698 commit 6e06629
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Wonju Jeon <wonju.jeon@navercorp.com>
ECrownofFire <ECrownofFire@gmail.com>
Artem Savienkov <as@attractgroup.com>
Hamid Sarfraz <praisedpk@gmail.com>
Alan Hamlett <alan.hamlett@gmail.com>
8 changes: 6 additions & 2 deletions src/ChartInternal/internals/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ export default {
* @private
*/
updateLegendItemColor(id: string, color: string): void {
this.$el.legend.select(`.${CLASS.legendItem}-${id} line`)
.style("stroke", color);
const {legend} = this.$el;

if (legend) {
legend.select(`.${CLASS.legendItem}-${id} line`)
.style("stroke", color);
}
},

/**
Expand Down
31 changes: 29 additions & 2 deletions test/internals/legend-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
/* eslint-disable */
/* global describe, beforeEach, it, expect */
import sinon from "sinon";
import {expect} from "chai";
import {select as d3Select} from "d3-selection";
import util from "../assets/util";
Expand Down Expand Up @@ -475,8 +476,8 @@ describe("LEGEND", () => {
});
});

describe('legend item tile coloring with color_treshold', () => {
before(function () {
describe("legend item tile coloring with color_treshold", () => {
before(() => {
args = {
data: {
columns: [
Expand Down Expand Up @@ -512,6 +513,32 @@ describe("LEGEND", () => {
expect(tileColor[2]).to.be.equal('rgb(249, 118, 0)');
expect(tileColor[3]).to.be.equal('rgb(255, 0, 0)');
});

it("color.threshold should be generated without error when legend.show=false", done => {
const spy = sinon.spy();

util.generate({
data: {
columns: [["col-0", 2.05]],
type: "gauge"
},
legend: {
show: false
},
color: {
pattern: ["#29BB9D", "#29BB9D", "#E7C248", "#FF9A0C", "#F56075"],
threshold: {
values: [20, 40, 60, 80, 100]
}
},
onrendered: spy
});

setTimeout(() => {
expect(spy.called).to.be.true;
done();
}, 500);
});
});

describe("legend item tile coloring without color_treshold", () => {
Expand Down

0 comments on commit 6e06629

Please sign in to comment.