@carbon/charts 0.54.13 → 0.54.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,13 @@ export declare class ColorScaleLegend extends Legend {
5
5
  renderType: RenderTypes;
6
6
  private gradient_id;
7
7
  init(): void;
8
- handleAxisComplete: (event: CustomEvent<any>) => void;
8
+ handleAxisCompleteEvent: (event: CustomEvent<any>) => void;
9
9
  render(animate?: boolean): void;
10
+ drawLinear(colorPairing: any, legendGroupElement: any, barWidth: any): void;
11
+ /**
12
+ * Renders quantized legend
13
+ * @returns number (range start)
14
+ */
15
+ drawQuantize(colorPairing: any, colorScheme: any, customColorsEnabled: any, legendGroupElement: any, barWidth: any): number;
10
16
  destroy(): void;
11
17
  }
@@ -20,7 +20,7 @@ import { DOMUtils } from '../../services';
20
20
  // D3 imports
21
21
  import { axisBottom } from 'd3-axis';
22
22
  import { scaleBand, scaleLinear } from 'd3-scale';
23
- import { interpolateRound, quantize } from 'd3-interpolate';
23
+ import { interpolateNumber, quantize } from 'd3-interpolate';
24
24
  var ColorScaleLegend = /** @class */ (function (_super) {
25
25
  __extends(ColorScaleLegend, _super);
26
26
  function ColorScaleLegend() {
@@ -28,7 +28,8 @@ var ColorScaleLegend = /** @class */ (function (_super) {
28
28
  _this.type = 'color-legend';
29
29
  _this.renderType = RenderTypes.SVG;
30
30
  _this.gradient_id = 'gradient-id-' + Math.floor(Math.random() * 99999999999);
31
- _this.handleAxisComplete = function (event) {
31
+ // Position legend after axis have rendered
32
+ _this.handleAxisCompleteEvent = function (event) {
32
33
  var svg = _this.getComponentContainer();
33
34
  var width = DOMUtils.getSVGElementSize(svg, {
34
35
  useAttrs: true,
@@ -37,7 +38,7 @@ var ColorScaleLegend = /** @class */ (function (_super) {
37
38
  if (width > Configuration.legend.color.barWidth && !isDataLoading) {
38
39
  var title = Tools.getProperty(_this.getOptions(), 'heatmap', 'colorLegend', 'title');
39
40
  var cartesianScales = _this.services.cartesianScales;
40
- // Get available chart area
41
+ // Get axis width & start/end positions
41
42
  var mainXScale = cartesianScales.getMainXScale();
42
43
  var xDimensions = mainXScale.range();
43
44
  // Align legend with the axis
@@ -45,9 +46,9 @@ var ColorScaleLegend = /** @class */ (function (_super) {
45
46
  svg.select('g.legend').attr('transform', "translate(" + xDimensions[0] + ", 0)");
46
47
  if (title) {
47
48
  var textWidth = DOMUtils.getSVGElementSize(svg.select('g.legend-title').select('text'), { useBBox: true }).width;
48
- // -9 since LEFT y-axis labels are moved towards the left by 9 by d3
49
+ // D3 moves the LEFT y-axis labels by 9
49
50
  var availableSpace = xDimensions[0] - textWidth - 9;
50
- // If space is available align the the label with the axis labels
51
+ // If space is available, align the label with the axis labels
51
52
  if (availableSpace > 1) {
52
53
  svg.select('g.legend-title').attr('transform', "translate(" + availableSpace + ", 0)");
53
54
  }
@@ -60,45 +61,50 @@ var ColorScaleLegend = /** @class */ (function (_super) {
60
61
  }
61
62
  }
62
63
  }
64
+ else {
65
+ // Default state
66
+ svg.select('g.legend-title').attr('transform', "translate(0, 0)");
67
+ }
63
68
  };
64
69
  return _this;
65
70
  }
66
71
  ColorScaleLegend.prototype.init = function () {
67
72
  var eventsFragment = this.services.events;
68
73
  // Highlight correct circle on legend item hovers
69
- eventsFragment.addEventListener(Events.Axis.RENDER_COMPLETE, this.handleAxisComplete);
74
+ eventsFragment.addEventListener(Events.Axis.RENDER_COMPLETE, this.handleAxisCompleteEvent);
70
75
  };
71
76
  ColorScaleLegend.prototype.render = function (animate) {
72
77
  if (animate === void 0) { animate = false; }
73
78
  var options = this.getOptions();
79
+ var svg = this.getComponentContainer();
80
+ var width = DOMUtils.getSVGElementSize(svg, {
81
+ useAttrs: true,
82
+ }).width;
74
83
  var customColors = Tools.getProperty(options, 'color', 'gradient', 'colors');
75
84
  var colorScaleType = Tools.getProperty(options, 'heatmap', 'colorLegend', 'type');
76
85
  var colorPairingOption = Tools.getProperty(options, 'color', 'pairing', 'option');
77
86
  var title = Tools.getProperty(options, 'heatmap', 'colorLegend', 'title');
78
- var customColorsEnabled = !Tools.isEmpty(customColors);
79
- var domain = this.model.getValueDomain();
80
- var svg = this.getComponentContainer();
81
87
  // Clear DOM if loading
82
88
  var isDataLoading = Tools.getProperty(this.getOptions(), 'data', 'loading');
83
89
  if (isDataLoading) {
84
90
  svg.html('');
85
91
  return;
86
92
  }
87
- var legend = DOMUtils.appendOrSelect(svg, 'g.legend');
88
- var axis = DOMUtils.appendOrSelect(legend, 'g.legend-axis');
89
- var width = DOMUtils.getSVGElementSize(svg, {
90
- useAttrs: true,
91
- }).width;
92
- var barWidth = Configuration.legend.color.barWidth;
93
- if (width <= Configuration.legend.color.barWidth) {
94
- barWidth = width;
95
- }
93
+ var customColorsEnabled = !Tools.isEmpty(customColors);
94
+ var domain = this.model.getValueDomain();
95
+ var useDefaultBarWidth = !(width <= Configuration.legend.color.barWidth);
96
+ var barWidth = useDefaultBarWidth
97
+ ? Configuration.legend.color.barWidth
98
+ : width;
99
+ var legendGroupElement = DOMUtils.appendOrSelect(svg, 'g.legend');
100
+ var axisElement = DOMUtils.appendOrSelect(legendGroupElement, 'g.legend-axis');
101
+ // Render title if it exists
96
102
  if (title) {
97
103
  var legendTitleGroup = DOMUtils.appendOrSelect(svg, 'g.legend-title');
98
104
  var legendTitle = DOMUtils.appendOrSelect(legendTitleGroup, 'text');
99
105
  legendTitle.text(title).attr('dy', '0.7em');
100
106
  // Move the legend down by 16 pixels to display legend text on top
101
- legend.attr('transform', "translate(0, 16)");
107
+ legendGroupElement.attr('transform', "translate(0, 16)");
102
108
  }
103
109
  // If domain consists of negative and positive values, use diverging palettes
104
110
  var colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';
@@ -128,107 +134,95 @@ var ColorScaleLegend = /** @class */ (function (_super) {
128
134
  // Use custom colors
129
135
  colorPairing = customColors;
130
136
  }
131
- if (colorScaleType === ColorLegendType.LINEAR) {
132
- var stopLengthPercentage_1 = 100 / (colorPairing.length - 1);
133
- // Generate the gradient
134
- var linearGradient = DOMUtils.appendOrSelect(legend, 'linearGradient');
135
- linearGradient
136
- .attr('id', this.gradient_id + "-legend")
137
- .selectAll('stop')
138
- .data(colorPairing)
139
- .enter()
140
- .append('stop')
141
- .attr('offset', function (_, i) { return i * stopLengthPercentage_1 + "%"; })
142
- .attr('class', function (_, i) { return colorPairing[i]; })
143
- .attr('stop-color', function (d) { return d; });
144
- // Create the legend container
145
- var rectangle = DOMUtils.appendOrSelect(legend, 'rect');
146
- rectangle
147
- .attr('width', barWidth)
148
- .attr('height', Configuration.legend.color.barHeight)
149
- .style('fill', "url(#" + this.gradient_id + "-legend)");
150
- // Create scale & ticks
151
- var linearScale = scaleLinear()
152
- .domain(domain)
153
- .range([0, barWidth]);
154
- domain.splice(1, 0, (domain[0] + domain[1]) / 2);
155
- var xAxis = axisBottom(linearScale)
156
- .tickSize(0)
157
- .tickValues(domain);
158
- // Align axes at the bottom of the rectangle and delete the domain line
159
- axis.attr('transform', "translate(0," + Configuration.legend.color.axisYTranslation + ")").call(xAxis);
160
- // Remove domain
161
- axis.select('.domain').remove();
162
- // Align text to fit in container
163
- axis.style('text-anchor', 'start');
164
- }
165
- else if (colorScaleType === ColorLegendType.QUANTIZE) {
166
- // Generate equal chunks between range to act as ticks
167
- var interpolator = interpolateRound(domain[0], domain[1]);
168
- var quant_1 = quantize(interpolator, colorPairing.length);
169
- // If divergent && non-custom color, remove 0/white from being displayed
170
- if (!customColorsEnabled && colorScheme === 'diverge') {
171
- colorPairing.splice(colorPairing.length / 2, 1);
172
- }
173
- var colorScaleBand_1 = scaleBand()
174
- .domain(colorPairing)
175
- .range([0, barWidth]);
176
- // Render the quantized rectangles
177
- var rectangle = DOMUtils.appendOrSelect(legend, 'g.quantized-rect');
178
- rectangle
179
- .selectAll('rect')
180
- .data(colorScaleBand_1.domain())
181
- .join('rect')
182
- .attr('x', function (d) { return colorScaleBand_1(d); })
183
- .attr('y', 0)
184
- .attr('width', Math.max(0, colorScaleBand_1.bandwidth()) - 1)
185
- .attr('height', Configuration.legend.color.barHeight)
186
- .attr('class', function (d) { return d; })
187
- .attr('fill', function (d) { return d; });
188
- var xAxis = axisBottom(colorScaleBand_1)
189
- .tickSize(0)
190
- .tickValues(colorPairing)
191
- .tickFormat(function (_, i) {
192
- // Display every other tick to create space
193
- if (!customColorsEnabled &&
194
- ((i + 1) % 2 === 0 || i === colorPairing.length - 1)) {
195
- return null;
196
- }
197
- // Use the quant interpolators as ticks
198
- return quant_1[i].toString();
199
- });
200
- // Align axis to match bandwidth start after initial (white)
201
- var axisTranslation = colorScaleBand_1.bandwidth() / 2;
202
- axis.attr('transform', "translate(" + (!customColorsEnabled && colorScheme === 'diverge' ? '-' : '') + axisTranslation + ", " + Configuration.legend.color.axisYTranslation + ")").call(xAxis);
203
- // Append the last tick
204
- var firstTick = axis.select('g.tick').clone(true);
205
- firstTick
206
- .attr('transform', "translate(" + (barWidth +
207
- (!customColorsEnabled && colorScheme === 'diverge'
208
- ? axisTranslation
209
- : -axisTranslation)) + ", 0)")
210
- .classed('final-tick', true)
211
- .select('text')
212
- .text(quant_1[quant_1.length - 1]);
213
- axis.enter().append(firstTick.node());
214
- axis.select('.domain').remove();
137
+ // Generate equal chunks between range to act as ticks
138
+ var interpolator = interpolateNumber(domain[0], domain[1]);
139
+ var quant = quantize(interpolator, 3);
140
+ // Create scale & ticks
141
+ var linearScale = scaleLinear().domain(domain).range([0, barWidth]);
142
+ var legendAxis = axisBottom(linearScale)
143
+ .tickSize(0)
144
+ .tickValues(quant);
145
+ switch (colorScaleType) {
146
+ case ColorLegendType.LINEAR:
147
+ this.drawLinear(colorPairing, legendGroupElement, barWidth);
148
+ break;
149
+ case ColorLegendType.QUANTIZE:
150
+ var rangeStart = this.drawQuantize(colorPairing, colorScheme, customColorsEnabled, legendGroupElement, barWidth);
151
+ // Using range provided by drawQuantize for alignment purposes
152
+ linearScale.range([rangeStart, barWidth]);
153
+ break;
154
+ default:
155
+ throw Error('Entered color legend type is not supported.');
215
156
  }
216
- else {
217
- throw Error('Entered color legend type is not supported.');
218
- }
219
- // Translate last axis tick if barWidth equals chart width
220
- if (width <= Configuration.legend.color.barWidth) {
221
- var lastTick = axis.select('g.tick:last-of-type text');
222
- var width_1 = DOMUtils.getSVGElementSize(lastTick, {
223
- useBBox: true,
224
- }).width;
225
- lastTick.attr('x', "-" + width_1);
157
+ // Align axes at the bottom of the rectangle and delete the domain line
158
+ axisElement
159
+ .attr('transform', "translate(0," + Configuration.legend.color.axisYTranslation + ")")
160
+ .call(legendAxis);
161
+ // Remove auto generated axis bottom line
162
+ axisElement.select('.domain').remove();
163
+ // Translate first/last axis tick if barWidth equals chart width
164
+ // Ensures text is not clipped when default bar width (300px) is not used
165
+ axisElement
166
+ .select('g.tick:last-of-type text')
167
+ .style('text-anchor', useDefaultBarWidth ? 'middle' : 'end');
168
+ axisElement
169
+ .select('g.tick:first-of-type text')
170
+ .style('text-anchor', useDefaultBarWidth ? 'middle' : 'start');
171
+ };
172
+ // Renders gradient legend
173
+ ColorScaleLegend.prototype.drawLinear = function (colorPairing, legendGroupElement, barWidth) {
174
+ var stopLengthPercentage = 100 / (colorPairing.length - 1);
175
+ // Generate the gradient
176
+ var linearGradient = DOMUtils.appendOrSelect(legendGroupElement, 'linearGradient');
177
+ // Rendering gradient
178
+ linearGradient
179
+ .attr('id', this.gradient_id + "-legend")
180
+ .selectAll('stop')
181
+ .data(colorPairing)
182
+ .enter()
183
+ .append('stop')
184
+ .attr('offset', function (_, i) { return i * stopLengthPercentage + "%"; })
185
+ .attr('class', function (_, i) { return colorPairing[i]; })
186
+ .attr('stop-color', function (d) { return d; });
187
+ // Create the legend container
188
+ var rectangle = DOMUtils.appendOrSelect(legendGroupElement, 'rect');
189
+ rectangle
190
+ .attr('width', barWidth)
191
+ .attr('height', Configuration.legend.color.barHeight)
192
+ .style('fill', "url(#" + this.gradient_id + "-legend)");
193
+ };
194
+ /**
195
+ * Renders quantized legend
196
+ * @returns number (range start)
197
+ */
198
+ ColorScaleLegend.prototype.drawQuantize = function (colorPairing, colorScheme, customColorsEnabled, legendGroupElement, barWidth) {
199
+ // If divergent && non-custom color, remove 0/white from being displayed
200
+ if (!customColorsEnabled && colorScheme === 'diverge') {
201
+ colorPairing.splice(colorPairing.length / 2, 1);
226
202
  }
203
+ var colorScaleBand = scaleBand()
204
+ .domain(colorPairing)
205
+ .range([0, barWidth]);
206
+ // Render the quantized rectangles
207
+ var rectangle = DOMUtils.appendOrSelect(legendGroupElement, 'g.quantized-rect');
208
+ rectangle
209
+ .selectAll('rect')
210
+ .data(colorScaleBand.domain())
211
+ .join('rect')
212
+ .attr('x', function (d) { return colorScaleBand(d); })
213
+ .attr('y', 0)
214
+ .attr('width', Math.max(0, colorScaleBand.bandwidth() - 1))
215
+ .attr('height', Configuration.legend.color.barHeight)
216
+ .attr('class', function (d) { return d; })
217
+ .attr('fill', function (d) { return d; });
218
+ return (!customColorsEnabled && colorScheme) === 'mono'
219
+ ? colorScaleBand.bandwidth() - 1
220
+ : 0;
227
221
  };
228
222
  ColorScaleLegend.prototype.destroy = function () {
229
223
  // Remove legend listeners
230
224
  var eventsFragment = this.services.events;
231
- eventsFragment.removeEventListener(Events.Axis.RENDER_COMPLETE, this.handleAxisComplete);
225
+ eventsFragment.removeEventListener(Events.Axis.RENDER_COMPLETE, this.handleAxisCompleteEvent);
232
226
  };
233
227
  return ColorScaleLegend;
234
228
  }(Legend));
@@ -1 +1 @@
1
- {"version":3,"file":"color-scale-legend.js","sourceRoot":"","sources":["color-scale-legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mBAAmB;AACnB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,O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AAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpD,SAAS;iBACP,IAAI,CACJ,WAAW,EACX,gBACC,QAAQ;gBACR,CAAC,CAAC,mBAAmB,IAAI,WAAW,KAAK,SAAS;oBACjD,CAAC,CAAC,eAAe;oBACjB,CAAC,CAAC,CAAC,eAAe,CAAC,UACf,CACN;iBACA,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC;iBAC3B,MAAM,CAAC,MAAM,CAAC;iBACd,IAAI,CAAC,OAAK,CAAC,OAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YAEhC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;SAChC;aAAM;YACN,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAC;SAC3D;QAED,0DAA0D;QAC1D,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;YACjD,IAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;YACjD,IAAA;;oBAAK,CAEV;YACH,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,MAAI,OAAO,CAAC,CAAC;SAChC;IACF,CAAC;IAED,kCAAO,GAAP;QACC,0BAA0B;QAC1B,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,cAAc,CAAC,mBAAmB,CACjC,MAAM,CAAC,IAAI,CAAC,eAAe,EAC3B,IAAI,CAAC,kBAAkB,CACvB,CAAC;IACH,CAAC;IACF,uBAAC;AAAD,CAAC,AArVD,CAAsC,MAAM,GAqV3C","sourcesContent":["// Internal Imports\nimport { Tools } from '../../tools';\nimport { ColorLegendType, Events, RenderTypes } from '../../interfaces';\nimport * as Configuration from '../../configuration';\nimport { Legend } from './legend';\nimport { DOMUtils } from '../../services';\n\n// D3 imports\nimport { axisBottom } from 'd3-axis';\nimport { scaleBand, scaleLinear } from 'd3-scale';\nimport { interpolateRound, quantize } from 'd3-interpolate';\n\nexport class ColorScaleLegend extends Legend {\n\ttype = 'color-legend';\n\trenderType = RenderTypes.SVG;\n\n\tprivate gradient_id =\n\t\t'gradient-id-' + Math.floor(Math.random() * 99999999999);\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct circle on legend item hovers\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisComplete\n\t\t);\n\t}\n\n\thandleAxisComplete = (event: CustomEvent) => {\n\t\tconst svg = this.getComponentContainer();\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (width > Configuration.legend.color.barWidth && !isDataLoading) {\n\t\t\tconst title = Tools.getProperty(\n\t\t\t\tthis.getOptions(),\n\t\t\t\t'heatmap',\n\t\t\t\t'colorLegend',\n\t\t\t\t'title'\n\t\t\t);\n\n\t\t\tconst { cartesianScales } = this.services;\n\t\t\t// Get available chart area\n\t\t\tconst mainXScale = cartesianScales.getMainXScale();\n\n\t\t\tconst xDimensions = mainXScale.range();\n\n\t\t\t// Align legend with the axis\n\t\t\tif (xDimensions[0] > 1) {\n\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t'transform',\n\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t);\n\n\t\t\t\tif (title) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\twidth: textWidth,\n\t\t\t\t\t} = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tsvg.select('g.legend-title').select('text'),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\n\t\t\t\t\t// -9 since LEFT y-axis labels are moved towards the left by 9 by d3\n\t\t\t\t\tconst availableSpace = xDimensions[0] - textWidth - 9;\n\n\t\t\t\t\t// If space is available align the the label with the axis labels\n\t\t\t\t\tif (availableSpace > 1) {\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${availableSpace}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 16)`\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Align legend title with start of axis\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\trender(animate = false) {\n\t\tconst options = this.getOptions();\n\n\t\tconst customColors = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'gradient',\n\t\t\t'colors'\n\t\t);\n\n\t\tconst colorScaleType = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'type'\n\t\t);\n\n\t\tlet colorPairingOption = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'pairing',\n\t\t\t'option'\n\t\t);\n\n\t\tconst title = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'title'\n\t\t);\n\n\t\tconst customColorsEnabled = !Tools.isEmpty(customColors);\n\t\tconst domain = this.model.getValueDomain();\n\n\t\tconst svg = this.getComponentContainer();\n\n\t\t// Clear DOM if loading\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (isDataLoading) {\n\t\t\tsvg.html('');\n\t\t\treturn;\n\t\t}\n\n\t\tconst legend = DOMUtils.appendOrSelect(svg, 'g.legend');\n\t\tconst axis = DOMUtils.appendOrSelect(legend, 'g.legend-axis');\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tlet barWidth = Configuration.legend.color.barWidth;\n\t\tif (width <= Configuration.legend.color.barWidth) {\n\t\t\tbarWidth = width;\n\t\t}\n\n\t\tif (title) {\n\t\t\tconst legendTitleGroup = DOMUtils.appendOrSelect(\n\t\t\t\tsvg,\n\t\t\t\t'g.legend-title'\n\t\t\t);\n\t\t\tconst legendTitle = DOMUtils.appendOrSelect(\n\t\t\t\tlegendTitleGroup,\n\t\t\t\t'text'\n\t\t\t);\n\t\t\tlegendTitle.text(title).attr('dy', '0.7em');\n\n\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\tlegend.attr('transform', `translate(0, 16)`);\n\t\t}\n\n\t\t// If domain consists of negative and positive values, use diverging palettes\n\t\tconst colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';\n\n\t\t// Use default color pairing options if not in defined range\n\t\tif (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 4 &&\n\t\t\tcolorScheme === 'mono'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t} else if (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 2 &&\n\t\t\tcolorScheme === 'diverge'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t}\n\n\t\tlet colorPairing = [];\n\t\t// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette\n\t\tlet colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;\n\n\t\tif (!customColorsEnabled) {\n\t\t\t// Add class names to list and the amount based on the color scheme\n\t\t\tfor (let i = 1; i < colorGroupingLength + 1; i++) {\n\t\t\t\tcolorPairing.push(\n\t\t\t\t\tcolorScaleType === ColorLegendType.LINEAR\n\t\t\t\t\t\t? `stop-color-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t\t\t: `fill-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\t// Use custom colors\n\t\t\tcolorPairing = customColors;\n\t\t}\n\n\t\tif (colorScaleType === ColorLegendType.LINEAR) {\n\t\t\tconst stopLengthPercentage = 100 / (colorPairing.length - 1);\n\n\t\t\t// Generate the gradient\n\t\t\tconst linearGradient = DOMUtils.appendOrSelect(\n\t\t\t\tlegend,\n\t\t\t\t'linearGradient'\n\t\t\t);\n\t\t\tlinearGradient\n\t\t\t\t.attr('id', `${this.gradient_id}-legend`)\n\t\t\t\t.selectAll('stop')\n\t\t\t\t.data(colorPairing)\n\t\t\t\t.enter()\n\t\t\t\t.append('stop')\n\t\t\t\t.attr('offset', (_, i) => `${i * stopLengthPercentage}%`)\n\t\t\t\t.attr('class', (_, i) => colorPairing[i])\n\t\t\t\t.attr('stop-color', (d) => d);\n\n\t\t\t// Create the legend container\n\t\t\tconst rectangle = DOMUtils.appendOrSelect(legend, 'rect');\n\t\t\trectangle\n\t\t\t\t.attr('width', barWidth)\n\t\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t\t.style('fill', `url(#${this.gradient_id}-legend)`);\n\n\t\t\t// Create scale & ticks\n\t\t\tconst linearScale = scaleLinear()\n\t\t\t\t.domain(domain)\n\t\t\t\t.range([0, barWidth]);\n\t\t\tdomain.splice(1, 0, (domain[0] + domain[1]) / 2);\n\n\t\t\tconst xAxis = axisBottom(linearScale)\n\t\t\t\t.tickSize(0)\n\t\t\t\t.tickValues(domain);\n\n\t\t\t// Align axes at the bottom of the rectangle and delete the domain line\n\t\t\taxis.attr(\n\t\t\t\t'transform',\n\t\t\t\t`translate(0,${Configuration.legend.color.axisYTranslation})`\n\t\t\t).call(xAxis);\n\n\t\t\t// Remove domain\n\t\t\taxis.select('.domain').remove();\n\n\t\t\t// Align text to fit in container\n\t\t\taxis.style('text-anchor', 'start');\n\t\t} else if (colorScaleType === ColorLegendType.QUANTIZE) {\n\t\t\t// Generate equal chunks between range to act as ticks\n\t\t\tconst interpolator = interpolateRound(domain[0], domain[1]);\n\t\t\tconst quant = quantize(interpolator, colorPairing.length);\n\n\t\t\t// If divergent && non-custom color, remove 0/white from being displayed\n\t\t\tif (!customColorsEnabled && colorScheme === 'diverge') {\n\t\t\t\tcolorPairing.splice(colorPairing.length / 2, 1);\n\t\t\t}\n\n\t\t\tconst colorScaleBand = scaleBand()\n\t\t\t\t.domain(colorPairing)\n\t\t\t\t.range([0, barWidth]);\n\n\t\t\t// Render the quantized rectangles\n\t\t\tconst rectangle = DOMUtils.appendOrSelect(\n\t\t\t\tlegend,\n\t\t\t\t'g.quantized-rect'\n\t\t\t);\n\n\t\t\trectangle\n\t\t\t\t.selectAll('rect')\n\t\t\t\t.data(colorScaleBand.domain())\n\t\t\t\t.join('rect')\n\t\t\t\t.attr('x', (d) => colorScaleBand(d))\n\t\t\t\t.attr('y', 0)\n\t\t\t\t.attr('width', Math.max(0, colorScaleBand.bandwidth()) - 1)\n\t\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t\t.attr('class', (d) => d)\n\t\t\t\t.attr('fill', (d) => d);\n\n\t\t\tconst xAxis = axisBottom(colorScaleBand)\n\t\t\t\t.tickSize(0)\n\t\t\t\t.tickValues(colorPairing)\n\t\t\t\t.tickFormat((_, i) => {\n\t\t\t\t\t// Display every other tick to create space\n\t\t\t\t\tif (\n\t\t\t\t\t\t!customColorsEnabled &&\n\t\t\t\t\t\t((i + 1) % 2 === 0 || i === colorPairing.length - 1)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Use the quant interpolators as ticks\n\t\t\t\t\treturn quant[i].toString();\n\t\t\t\t});\n\n\t\t\t// Align axis to match bandwidth start after initial (white)\n\t\t\tconst axisTranslation = colorScaleBand.bandwidth() / 2;\n\t\t\taxis.attr(\n\t\t\t\t'transform',\n\t\t\t\t`translate(${\n\t\t\t\t\t!customColorsEnabled && colorScheme === 'diverge' ? '-' : ''\n\t\t\t\t}${axisTranslation}, ${\n\t\t\t\t\tConfiguration.legend.color.axisYTranslation\n\t\t\t\t})`\n\t\t\t).call(xAxis);\n\n\t\t\t// Append the last tick\n\t\t\tconst firstTick = axis.select('g.tick').clone(true);\n\t\t\tfirstTick\n\t\t\t\t.attr(\n\t\t\t\t\t'transform',\n\t\t\t\t\t`translate(${\n\t\t\t\t\t\tbarWidth +\n\t\t\t\t\t\t(!customColorsEnabled && colorScheme === 'diverge'\n\t\t\t\t\t\t\t? axisTranslation\n\t\t\t\t\t\t\t: -axisTranslation)\n\t\t\t\t\t}, 0)`\n\t\t\t\t)\n\t\t\t\t.classed('final-tick', true)\n\t\t\t\t.select('text')\n\t\t\t\t.text(quant[quant.length - 1]);\n\n\t\t\taxis.enter().append(firstTick.node());\n\t\t\taxis.select('.domain').remove();\n\t\t} else {\n\t\t\tthrow Error('Entered color legend type is not supported.');\n\t\t}\n\n\t\t// Translate last axis tick if barWidth equals chart width\n\t\tif (width <= Configuration.legend.color.barWidth) {\n\t\t\tconst lastTick = axis.select('g.tick:last-of-type text');\n\t\t\tconst { width } = DOMUtils.getSVGElementSize(lastTick, {\n\t\t\t\tuseBBox: true,\n\t\t\t});\n\t\t\tlastTick.attr('x', `-${width}`);\n\t\t}\n\t}\n\n\tdestroy() {\n\t\t// Remove legend listeners\n\t\tconst eventsFragment = this.services.events;\n\t\teventsFragment.removeEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisComplete\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"color-scale-legend.js","sourceRoot":"","sources":["color-scale-legend.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mB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M,CAAC,KAAK,CAAC,SAAS,CAAC;aACpD,IAAI,CAAC,OAAO,EAAE,UAAC,CAAC,IAAK,OAAA,CAAC,EAAD,CAAC,CAAC;aACvB,IAAI,CAAC,MAAM,EAAE,UAAC,CAAC,IAAK,OAAA,CAAC,EAAD,CAAC,CAAC,CAAC;QAEzB,OAAO,CAAC,CAAC,mBAAmB,IAAI,WAAW,CAAC,KAAK,MAAM;YACtD,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC;YAChC,CAAC,CAAC,CAAC,CAAC;IACN,CAAC;IAED,kCAAO,GAAP;QACC,0BAA0B;QAC1B,IAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,cAAc,CAAC,mBAAmB,CACjC,MAAM,CAAC,IAAI,CAAC,eAAe,EAC3B,IAAI,CAAC,uBAAuB,CAC5B,CAAC;IACH,CAAC;IACF,uBAAC;AAAD,CAAC,AA9UD,CAAsC,MAAM,GA8U3C","sourcesContent":["// Internal Imports\nimport { Tools } from '../../tools';\nimport { ColorLegendType, Events, RenderTypes } from '../../interfaces';\nimport * as Configuration from '../../configuration';\nimport { Legend } from './legend';\nimport { DOMUtils } from '../../services';\n\n// D3 imports\nimport { axisBottom } from 'd3-axis';\nimport { scaleBand, scaleLinear } from 'd3-scale';\nimport { interpolateNumber, quantize } from 'd3-interpolate';\n\nexport class ColorScaleLegend extends Legend {\n\ttype = 'color-legend';\n\trenderType = RenderTypes.SVG;\n\n\tprivate gradient_id =\n\t\t'gradient-id-' + Math.floor(Math.random() * 99999999999);\n\n\tinit() {\n\t\tconst eventsFragment = this.services.events;\n\n\t\t// Highlight correct circle on legend item hovers\n\t\teventsFragment.addEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisCompleteEvent\n\t\t);\n\t}\n\n\t// Position legend after axis have rendered\n\thandleAxisCompleteEvent = (event: CustomEvent) => {\n\t\tconst svg = this.getComponentContainer();\n\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (width > Configuration.legend.color.barWidth && !isDataLoading) {\n\t\t\tconst title = Tools.getProperty(\n\t\t\t\tthis.getOptions(),\n\t\t\t\t'heatmap',\n\t\t\t\t'colorLegend',\n\t\t\t\t'title'\n\t\t\t);\n\n\t\t\tconst { cartesianScales } = this.services;\n\n\t\t\t// Get axis width & start/end positions\n\t\t\tconst mainXScale = cartesianScales.getMainXScale();\n\t\t\tconst xDimensions = mainXScale.range();\n\n\t\t\t// Align legend with the axis\n\t\t\tif (xDimensions[0] > 1) {\n\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t'transform',\n\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t);\n\n\t\t\t\tif (title) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\twidth: textWidth,\n\t\t\t\t\t} = DOMUtils.getSVGElementSize(\n\t\t\t\t\t\tsvg.select('g.legend-title').select('text'),\n\t\t\t\t\t\t{ useBBox: true }\n\t\t\t\t\t);\n\n\t\t\t\t\t// D3 moves the LEFT y-axis labels by 9\n\t\t\t\t\tconst availableSpace = xDimensions[0] - textWidth - 9;\n\n\t\t\t\t\t// If space is available, align the label with the axis labels\n\t\t\t\t\tif (availableSpace > 1) {\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${availableSpace}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\t\t\t\tsvg.select('g.legend').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 16)`\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Align legend title with start of axis\n\t\t\t\t\t\tsvg.select('g.legend-title').attr(\n\t\t\t\t\t\t\t'transform',\n\t\t\t\t\t\t\t`translate(${xDimensions[0]}, 0)`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Default state\n\t\t\tsvg.select('g.legend-title').attr('transform', `translate(0, 0)`);\n\t\t}\n\t};\n\n\trender(animate = false) {\n\t\tconst options = this.getOptions();\n\t\tconst svg = this.getComponentContainer();\n\t\tconst { width } = DOMUtils.getSVGElementSize(svg, {\n\t\t\tuseAttrs: true,\n\t\t});\n\n\t\tconst customColors = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'gradient',\n\t\t\t'colors'\n\t\t);\n\n\t\tconst colorScaleType = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'type'\n\t\t);\n\n\t\tlet colorPairingOption = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'color',\n\t\t\t'pairing',\n\t\t\t'option'\n\t\t);\n\n\t\tconst title = Tools.getProperty(\n\t\t\toptions,\n\t\t\t'heatmap',\n\t\t\t'colorLegend',\n\t\t\t'title'\n\t\t);\n\n\t\t// Clear DOM if loading\n\t\tconst isDataLoading = Tools.getProperty(\n\t\t\tthis.getOptions(),\n\t\t\t'data',\n\t\t\t'loading'\n\t\t);\n\n\t\tif (isDataLoading) {\n\t\t\tsvg.html('');\n\t\t\treturn;\n\t\t}\n\n\t\tconst customColorsEnabled = !Tools.isEmpty(customColors);\n\t\tconst domain = this.model.getValueDomain();\n\n\t\tconst useDefaultBarWidth = !(\n\t\t\twidth <= Configuration.legend.color.barWidth\n\t\t);\n\t\tconst barWidth = useDefaultBarWidth\n\t\t\t? Configuration.legend.color.barWidth\n\t\t\t: width;\n\n\t\tconst legendGroupElement = DOMUtils.appendOrSelect(svg, 'g.legend');\n\t\tconst axisElement = DOMUtils.appendOrSelect(\n\t\t\tlegendGroupElement,\n\t\t\t'g.legend-axis'\n\t\t);\n\n\t\t// Render title if it exists\n\t\tif (title) {\n\t\t\tconst legendTitleGroup = DOMUtils.appendOrSelect(\n\t\t\t\tsvg,\n\t\t\t\t'g.legend-title'\n\t\t\t);\n\t\t\tconst legendTitle = DOMUtils.appendOrSelect(\n\t\t\t\tlegendTitleGroup,\n\t\t\t\t'text'\n\t\t\t);\n\t\t\tlegendTitle.text(title).attr('dy', '0.7em');\n\n\t\t\t// Move the legend down by 16 pixels to display legend text on top\n\t\t\tlegendGroupElement.attr('transform', `translate(0, 16)`);\n\t\t}\n\n\t\t// If domain consists of negative and positive values, use diverging palettes\n\t\tconst colorScheme = domain[0] < 0 && domain[1] > 0 ? 'diverge' : 'mono';\n\n\t\t// Use default color pairing options if not in defined range\n\t\tif (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 4 &&\n\t\t\tcolorScheme === 'mono'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t} else if (\n\t\t\tcolorPairingOption < 1 &&\n\t\t\tcolorPairingOption > 2 &&\n\t\t\tcolorScheme === 'diverge'\n\t\t) {\n\t\t\tcolorPairingOption = 1;\n\t\t}\n\n\t\tlet colorPairing = [];\n\t\t// Carbon charts has 11 colors for a single monochromatic palette & 17 for a divergent palette\n\t\tlet colorGroupingLength = colorScheme === 'diverge' ? 17 : 11;\n\n\t\tif (!customColorsEnabled) {\n\t\t\t// Add class names to list and the amount based on the color scheme\n\t\t\tfor (let i = 1; i < colorGroupingLength + 1; i++) {\n\t\t\t\tcolorPairing.push(\n\t\t\t\t\tcolorScaleType === ColorLegendType.LINEAR\n\t\t\t\t\t\t? `stop-color-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t\t\t: `fill-${colorScheme}-${colorPairingOption}-${i}`\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\t// Use custom colors\n\t\t\tcolorPairing = customColors;\n\t\t}\n\n\t\t// Generate equal chunks between range to act as ticks\n\t\tconst interpolator = interpolateNumber(domain[0], domain[1]);\n\t\tconst quant = quantize(interpolator, 3);\n\n\t\t// Create scale & ticks\n\t\tconst linearScale = scaleLinear().domain(domain).range([0, barWidth]);\n\n\t\tconst legendAxis = axisBottom(linearScale)\n\t\t\t.tickSize(0)\n\t\t\t.tickValues(quant);\n\n\t\tswitch (colorScaleType) {\n\t\t\tcase ColorLegendType.LINEAR:\n\t\t\t\tthis.drawLinear(colorPairing, legendGroupElement, barWidth);\n\t\t\t\tbreak;\n\t\t\tcase ColorLegendType.QUANTIZE:\n\t\t\t\tconst rangeStart = this.drawQuantize(\n\t\t\t\t\tcolorPairing,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t\tcustomColorsEnabled,\n\t\t\t\t\tlegendGroupElement,\n\t\t\t\t\tbarWidth\n\t\t\t\t);\n\t\t\t\t// Using range provided by drawQuantize for alignment purposes\n\t\t\t\tlinearScale.range([rangeStart, barWidth]);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow Error('Entered color legend type is not supported.');\n\t\t}\n\n\t\t// Align axes at the bottom of the rectangle and delete the domain line\n\t\taxisElement\n\t\t\t.attr(\n\t\t\t\t'transform',\n\t\t\t\t`translate(0,${Configuration.legend.color.axisYTranslation})`\n\t\t\t)\n\t\t\t.call(legendAxis);\n\n\t\t// Remove auto generated axis bottom line\n\t\taxisElement.select('.domain').remove();\n\n\t\t// Translate first/last axis tick if barWidth equals chart width\n\t\t// Ensures text is not clipped when default bar width (300px) is not used\n\t\taxisElement\n\t\t\t.select('g.tick:last-of-type text')\n\t\t\t.style('text-anchor', useDefaultBarWidth ? 'middle' : 'end');\n\t\taxisElement\n\t\t\t.select('g.tick:first-of-type text')\n\t\t\t.style('text-anchor', useDefaultBarWidth ? 'middle' : 'start');\n\t}\n\n\t// Renders gradient legend\n\tdrawLinear(colorPairing, legendGroupElement, barWidth) {\n\t\tconst stopLengthPercentage = 100 / (colorPairing.length - 1);\n\n\t\t// Generate the gradient\n\t\tconst linearGradient = DOMUtils.appendOrSelect(\n\t\t\tlegendGroupElement,\n\t\t\t'linearGradient'\n\t\t);\n\t\t// Rendering gradient\n\t\tlinearGradient\n\t\t\t.attr('id', `${this.gradient_id}-legend`)\n\t\t\t.selectAll('stop')\n\t\t\t.data(colorPairing)\n\t\t\t.enter()\n\t\t\t.append('stop')\n\t\t\t.attr('offset', (_, i) => `${i * stopLengthPercentage}%`)\n\t\t\t.attr('class', (_, i) => colorPairing[i])\n\t\t\t.attr('stop-color', (d) => d);\n\n\t\t// Create the legend container\n\t\tconst rectangle = DOMUtils.appendOrSelect(legendGroupElement, 'rect');\n\t\trectangle\n\t\t\t.attr('width', barWidth)\n\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t.style('fill', `url(#${this.gradient_id}-legend)`);\n\t}\n\n\t/**\n\t * Renders quantized legend\n\t * @returns number (range start)\n\t */\n\tdrawQuantize(\n\t\tcolorPairing,\n\t\tcolorScheme,\n\t\tcustomColorsEnabled,\n\t\tlegendGroupElement,\n\t\tbarWidth\n\t) {\n\t\t// If divergent && non-custom color, remove 0/white from being displayed\n\t\tif (!customColorsEnabled && colorScheme === 'diverge') {\n\t\t\tcolorPairing.splice(colorPairing.length / 2, 1);\n\t\t}\n\n\t\tconst colorScaleBand = scaleBand()\n\t\t\t.domain(colorPairing)\n\t\t\t.range([0, barWidth]);\n\n\t\t// Render the quantized rectangles\n\t\tconst rectangle = DOMUtils.appendOrSelect(\n\t\t\tlegendGroupElement,\n\t\t\t'g.quantized-rect'\n\t\t);\n\n\t\trectangle\n\t\t\t.selectAll('rect')\n\t\t\t.data(colorScaleBand.domain())\n\t\t\t.join('rect')\n\t\t\t.attr('x', (d) => colorScaleBand(d))\n\t\t\t.attr('y', 0)\n\t\t\t.attr('width', Math.max(0, colorScaleBand.bandwidth() - 1))\n\t\t\t.attr('height', Configuration.legend.color.barHeight)\n\t\t\t.attr('class', (d) => d)\n\t\t\t.attr('fill', (d) => d);\n\n\t\treturn (!customColorsEnabled && colorScheme) === 'mono'\n\t\t\t? colorScaleBand.bandwidth() - 1\n\t\t\t: 0;\n\t}\n\n\tdestroy() {\n\t\t// Remove legend listeners\n\t\tconst eventsFragment = this.services.events;\n\t\teventsFragment.removeEventListener(\n\t\t\tEvents.Axis.RENDER_COMPLETE,\n\t\t\tthis.handleAxisCompleteEvent\n\t\t);\n\t}\n}\n"]}