diff --git a/AUTHORS.txt b/AUTHORS.txt index bb5d817f2..881e4d483 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -41,3 +41,4 @@ Wonju Jeon ECrownofFire Artem Savienkov Hamid Sarfraz +Alan Hamlett diff --git a/src/ChartInternal/internals/legend.ts b/src/ChartInternal/internals/legend.ts index b21356890..1bd689332 100644 --- a/src/ChartInternal/internals/legend.ts +++ b/src/ChartInternal/internals/legend.ts @@ -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); + } }, /** diff --git a/test/internals/legend-spec.ts b/test/internals/legend-spec.ts index 2b0fd536d..93d7e6906 100644 --- a/test/internals/legend-spec.ts +++ b/test/internals/legend-spec.ts @@ -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"; @@ -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: [ @@ -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", () => {