pict-section-form 1.3.10 → 1.3.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "description": "Pict dynamic forms",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+ /**
3
+ * Scoped CSS for the chart input's grouped legend. Registered once by
4
+ * Pict-Provider-Input-Chart via
5
+ * `pict.CSSMap.addCSS('Pict-Input-Chart-CSS', libCSS, 500)`.
6
+ *
7
+ * Chart.js's own legend is a single flow-wrapped row of swatches. On a control
8
+ * chart that is eight entries of near-identical colour, with the limit lines
9
+ * indistinguishable from the readings, wrapping into an unreadable block. This
10
+ * legend is a vertical list, grouped, with each group toggleable as a unit.
11
+ *
12
+ * Everything is themeable through the --theme-color-* tokens; the hardcoded
13
+ * values are fallbacks.
14
+ */
15
+ const libCSS = /*css*/`
16
+ .pict-chart-shell { display: flex; align-items: stretch; gap: 0.75rem; width: 100%; }
17
+ .pict-chart-shell.pict-chart-legend-top { flex-direction: column-reverse; }
18
+ .pict-chart-shell.pict-chart-legend-bottom { flex-direction: column; }
19
+ .pict-chart-shell .pict-chart-canvas-area { flex: 1 1 auto; min-width: 0; position: relative; }
20
+
21
+ .pict-chart-legend { flex: 0 0 auto; max-width: 15rem; font-size: 0.78rem; line-height: 1.35;
22
+ color: var(--theme-color-text-primary, #1f2733); user-select: none; }
23
+ .pict-chart-legend-top .pict-chart-legend,
24
+ .pict-chart-legend-bottom .pict-chart-legend { max-width: none; }
25
+
26
+ .pict-chart-legend-group + .pict-chart-legend-group { margin-top: 0.5rem; }
27
+ .pict-chart-legend-group-header { display: flex; align-items: center; gap: 0.35rem; cursor: pointer;
28
+ font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
29
+ color: var(--theme-color-text-muted, #6b7686); padding: 0.15rem 0; }
30
+ .pict-chart-legend-group-header:hover { color: var(--theme-color-text-primary, #1f2733); }
31
+ .pict-chart-legend-group-caret { font-size: 0.6rem; transition: transform 0.12s ease; }
32
+ .pict-chart-legend-group.pict-collapsed .pict-chart-legend-group-caret { transform: rotate(-90deg); }
33
+ .pict-chart-legend-group.pict-collapsed .pict-chart-legend-items { display: none; }
34
+ /* A group whose series are ALL hidden is dimmed as a whole, so the group toggle
35
+ reads as a control rather than decoration. */
36
+ .pict-chart-legend-group.pict-group-off .pict-chart-legend-group-header { opacity: 0.45; }
37
+
38
+ .pict-chart-legend-items { display: flex; flex-direction: column; gap: 0.1rem; }
39
+ .pict-chart-legend-top .pict-chart-legend-items,
40
+ .pict-chart-legend-bottom .pict-chart-legend-items { flex-direction: row; flex-wrap: wrap; gap: 0.1rem 0.75rem; }
41
+
42
+ .pict-chart-legend-item { display: flex; align-items: center; gap: 0.4rem; cursor: pointer;
43
+ padding: 0.1rem 0.2rem; border-radius: 4px; }
44
+ .pict-chart-legend-item:hover { background: var(--theme-color-background-hover, rgba(0,0,0,0.04)); }
45
+ .pict-chart-legend-item.pict-hidden { opacity: 0.4; }
46
+ .pict-chart-legend-item.pict-hidden .pict-chart-legend-label { text-decoration: line-through; }
47
+ .pict-chart-legend-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
48
+
49
+ /* The swatch carries the series' identity: colour, and whether it is a solid
50
+ line, a dashed one, or unconnected markers. A legend that shows every entry
51
+ as the same solid block cannot distinguish a reading from its control limit. */
52
+ .pict-chart-legend-swatch { flex: 0 0 auto; width: 1.4rem; height: 0.7rem; position: relative; }
53
+ .pict-chart-legend-swatch::before { content: ''; position: absolute; left: 0; right: 0; top: 50%;
54
+ transform: translateY(-50%); height: 0.15rem; border-radius: 1px; background: currentColor; }
55
+ .pict-chart-legend-swatch.pict-swatch-dashed::before {
56
+ background: repeating-linear-gradient(to right, currentColor 0 0.28rem, transparent 0.28rem 0.5rem); }
57
+ .pict-chart-legend-swatch.pict-swatch-dotted::before {
58
+ background: repeating-linear-gradient(to right, currentColor 0 0.12rem, transparent 0.12rem 0.28rem); }
59
+ .pict-chart-legend-swatch.pict-swatch-markers::before { display: none; }
60
+ .pict-chart-legend-swatch.pict-swatch-markers::after { content: ''; position: absolute; left: 50%; top: 50%;
61
+ transform: translate(-50%, -50%); width: 0.45rem; height: 0.45rem; border-radius: 50%; background: currentColor; }
62
+
63
+ .pict-chart-legend-toggle { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer;
64
+ font-size: 0.68rem; color: var(--theme-color-text-muted, #6b7686);
65
+ background: none; border: 1px solid var(--theme-color-border-light, #e8ebf0);
66
+ border-radius: 5px; padding: 0.1rem 0.4rem; margin-bottom: 0.35rem; }
67
+ .pict-chart-legend-toggle:hover { color: var(--theme-color-text-primary, #1f2733);
68
+ border-color: var(--theme-color-border-strong, #c2c9d2); }
69
+ `;
70
+
71
+ module.exports = libCSS;
@@ -1,4 +1,5 @@
1
1
  const libPictSectionInputExtension = require('../Pict-Provider-InputExtension.js');
2
+ const libChartCSS = require('./Pict-Provider-Input-Chart-CSS.js');
2
3
 
3
4
  /**
4
5
  * CustomInputHandler class.
@@ -127,6 +128,209 @@ class CustomInputHandler extends libPictSectionInputExtension
127
128
 
128
129
  this.currentChartObjects = {};
129
130
  this.currentChartDataObjects = {};
131
+ // Legend visibility + collapsed groups, per input hash, so a redraw does not
132
+ // undo what the user toggled.
133
+ this.currentChartLegendState = {};
134
+
135
+ if (this.pict && this.pict.CSSMap && typeof this.pict.CSSMap.addCSS === 'function')
136
+ {
137
+ this.pict.CSSMap.addCSS('Pict-Input-Chart-CSS', libChartCSS, 500);
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Classify a dataset's line style for its legend swatch, so a reading, a
143
+ * dashed control limit and an unconnected marker series are told apart at a
144
+ * glance. Chart.js's own legend draws every entry as the same block.
145
+ *
146
+ * @param {Object} pDataset - The Chart.js dataset.
147
+ * @return {string} A swatch modifier class.
148
+ */
149
+ _legendSwatchClass(pDataset)
150
+ {
151
+ if (pDataset.showLine === false) { return 'pict-swatch-markers'; }
152
+ const tmpDash = Array.isArray(pDataset.borderDash) ? pDataset.borderDash : null;
153
+ if (!tmpDash || tmpDash.length < 1) { return ''; }
154
+ // A short first segment reads as dotted, a long one as dashed.
155
+ return (Number(tmpDash[0]) <= 3) ? 'pict-swatch-dotted' : 'pict-swatch-dashed';
156
+ }
157
+
158
+ /**
159
+ * Group the datasets for the legend. A dataset declares its group with
160
+ * `LegendGroup` on the solver entry (carried onto the dataset as
161
+ * `pictLegendGroup`); anything that does not is "Data". Group ORDER follows
162
+ * first appearance, so configuration controls it rather than sort order.
163
+ *
164
+ * @param {Object} pChart - The Chart.js instance.
165
+ * @return {Array<{Key: string, Items: Array<{Index: number, Dataset: Object}>}>}
166
+ */
167
+ _legendGroups(pChart)
168
+ {
169
+ const tmpGroups = [];
170
+ const tmpIndex = {};
171
+ const tmpDatasets = (pChart && pChart.data && pChart.data.datasets) || [];
172
+ for (let i = 0; i < tmpDatasets.length; i++)
173
+ {
174
+ const tmpKey = tmpDatasets[i].pictLegendGroup || 'Data';
175
+ if (!(tmpKey in tmpIndex))
176
+ {
177
+ tmpIndex[tmpKey] = tmpGroups.length;
178
+ tmpGroups.push({ Key: tmpKey, Items: [] });
179
+ }
180
+ tmpGroups[tmpIndex[tmpKey]].Items.push({ Index: i, Dataset: tmpDatasets[i] });
181
+ }
182
+ return tmpGroups;
183
+ }
184
+
185
+ /**
186
+ * Build (or rebuild) the grouped HTML legend beside a chart's canvas.
187
+ *
188
+ * The legend is created in the DOM rather than in the template because there
189
+ * are several chart templates (the base set plus per-theme copies) and a
190
+ * legend added to only some of them is the kind of divergence that goes
191
+ * unnoticed. Chart.js's built-in legend is switched off whenever this runs.
192
+ *
193
+ * @param {string} pRawHTMLID - The input's Macro.RawHTMLID.
194
+ * @param {Object} pChart - The Chart.js instance.
195
+ * @param {Object} pLegendConfiguration - The resolved ChartLegend config.
196
+ */
197
+ renderChartLegend(pRawHTMLID, pChart, pLegendConfiguration)
198
+ {
199
+ if (typeof (document) === 'undefined' || !pChart || !pChart.canvas) { return false; }
200
+ const tmpCanvas = pChart.canvas;
201
+ const tmpContainer = tmpCanvas.parentElement;
202
+ if (!tmpContainer) { return false; }
203
+
204
+ const tmpState = this.currentChartLegendState[pRawHTMLID] = this.currentChartLegendState[pRawHTMLID] || { Hidden: false, Collapsed: {} };
205
+ const tmpPosition = pLegendConfiguration.Position || 'right';
206
+
207
+ // Wrap the canvas once: shell > (canvas area | legend).
208
+ let tmpShell = tmpContainer.parentElement && tmpContainer.parentElement.classList.contains('pict-chart-shell')
209
+ ? tmpContainer.parentElement : null;
210
+ if (!tmpShell)
211
+ {
212
+ tmpShell = document.createElement('div');
213
+ tmpShell.className = 'pict-chart-shell';
214
+ tmpContainer.parentNode.insertBefore(tmpShell, tmpContainer);
215
+ const tmpArea = document.createElement('div');
216
+ tmpArea.className = 'pict-chart-canvas-area';
217
+ tmpShell.appendChild(tmpArea);
218
+ tmpArea.appendChild(tmpContainer);
219
+ }
220
+ tmpShell.classList.remove('pict-chart-legend-top', 'pict-chart-legend-bottom');
221
+ if (tmpPosition === 'top') { tmpShell.classList.add('pict-chart-legend-top'); }
222
+ if (tmpPosition === 'bottom') { tmpShell.classList.add('pict-chart-legend-bottom'); }
223
+
224
+ let tmpLegend = tmpShell.querySelector(':scope > .pict-chart-legend');
225
+ if (!tmpLegend)
226
+ {
227
+ tmpLegend = document.createElement('div');
228
+ tmpLegend.className = 'pict-chart-legend';
229
+ tmpShell.appendChild(tmpLegend);
230
+ }
231
+ tmpLegend.innerHTML = '';
232
+
233
+ // Show/hide the whole legend. Charts differ in how much room they have,
234
+ // so this is per-chart and remembered for the session.
235
+ if (pLegendConfiguration.AllowHide !== false)
236
+ {
237
+ const tmpToggle = document.createElement('button');
238
+ tmpToggle.type = 'button';
239
+ tmpToggle.className = 'pict-chart-legend-toggle';
240
+ tmpToggle.textContent = tmpState.Hidden ? 'Show legend' : 'Hide legend';
241
+ tmpToggle.addEventListener('click', () =>
242
+ {
243
+ tmpState.Hidden = !tmpState.Hidden;
244
+ this.renderChartLegend(pRawHTMLID, pChart, pLegendConfiguration);
245
+ });
246
+ tmpLegend.appendChild(tmpToggle);
247
+ }
248
+ if (tmpState.Hidden) { return true; }
249
+
250
+ const tmpGroups = this._legendGroups(pChart);
251
+ for (const tmpGroup of tmpGroups)
252
+ {
253
+ const tmpGroupElement = document.createElement('div');
254
+ tmpGroupElement.className = 'pict-chart-legend-group';
255
+ const tmpAllHidden = tmpGroup.Items.every((pItem) => pChart.getDatasetMeta(pItem.Index).hidden === true);
256
+ if (tmpAllHidden) { tmpGroupElement.classList.add('pict-group-off'); }
257
+ if (tmpState.Collapsed[tmpGroup.Key]) { tmpGroupElement.classList.add('pict-collapsed'); }
258
+
259
+ const tmpHeader = document.createElement('div');
260
+ tmpHeader.className = 'pict-chart-legend-group-header';
261
+ const tmpCaret = document.createElement('span');
262
+ tmpCaret.className = 'pict-chart-legend-group-caret';
263
+ tmpCaret.textContent = '▾';
264
+ tmpHeader.appendChild(tmpCaret);
265
+ const tmpHeaderLabel = document.createElement('span');
266
+ tmpHeaderLabel.textContent = tmpGroup.Key;
267
+ tmpHeader.appendChild(tmpHeaderLabel);
268
+ // Header click toggles the GROUP's series on/off; the caret collapses it.
269
+ tmpHeader.addEventListener('click', (pEvent) =>
270
+ {
271
+ if (pEvent.target === tmpCaret)
272
+ {
273
+ tmpState.Collapsed[tmpGroup.Key] = !tmpState.Collapsed[tmpGroup.Key];
274
+ }
275
+ else
276
+ {
277
+ const tmpTurnOn = tmpAllHidden;
278
+ for (const tmpItem of tmpGroup.Items)
279
+ {
280
+ pChart.getDatasetMeta(tmpItem.Index).hidden = tmpTurnOn ? false : true;
281
+ }
282
+ pChart.update();
283
+ }
284
+ this.renderChartLegend(pRawHTMLID, pChart, pLegendConfiguration);
285
+ });
286
+ tmpGroupElement.appendChild(tmpHeader);
287
+
288
+ const tmpItems = document.createElement('div');
289
+ tmpItems.className = 'pict-chart-legend-items';
290
+ for (const tmpItem of tmpGroup.Items)
291
+ {
292
+ const tmpHidden = pChart.getDatasetMeta(tmpItem.Index).hidden === true;
293
+ const tmpItemElement = document.createElement('div');
294
+ tmpItemElement.className = 'pict-chart-legend-item' + (tmpHidden ? ' pict-hidden' : '');
295
+ const tmpSwatch = document.createElement('span');
296
+ tmpSwatch.className = ('pict-chart-legend-swatch ' + this._legendSwatchClass(tmpItem.Dataset)).trim();
297
+ tmpSwatch.style.color = tmpItem.Dataset.borderColor || tmpItem.Dataset.backgroundColor || '#868E96';
298
+ tmpItemElement.appendChild(tmpSwatch);
299
+ const tmpLabel = document.createElement('span');
300
+ tmpLabel.className = 'pict-chart-legend-label';
301
+ tmpLabel.textContent = tmpItem.Dataset.label || `Series ${tmpItem.Index + 1}`;
302
+ tmpLabel.title = tmpLabel.textContent;
303
+ tmpItemElement.appendChild(tmpLabel);
304
+ tmpItemElement.addEventListener('click', () =>
305
+ {
306
+ pChart.getDatasetMeta(tmpItem.Index).hidden = !tmpHidden;
307
+ pChart.update();
308
+ this.renderChartLegend(pRawHTMLID, pChart, pLegendConfiguration);
309
+ });
310
+ tmpItems.appendChild(tmpItemElement);
311
+ }
312
+ tmpGroupElement.appendChild(tmpItems);
313
+ tmpLegend.appendChild(tmpGroupElement);
314
+ }
315
+ return true;
316
+ }
317
+
318
+ /**
319
+ * Resolve the ChartLegend configuration for an input. Returns null when the
320
+ * grouped legend is not in use, in which case Chart.js's own legend stands.
321
+ *
322
+ * @param {Object} pInput - The PictForm input object.
323
+ * @return {Object|null}
324
+ */
325
+ resolveChartLegendConfiguration(pInput)
326
+ {
327
+ const tmpPictform = (pInput && pInput.PictForm) || {};
328
+ const tmpLegend = tmpPictform.ChartLegend;
329
+ if (!tmpLegend) { return null; }
330
+ if (tmpLegend === true) { return { Position: 'right' }; }
331
+ if (typeof (tmpLegend) !== 'object') { return null; }
332
+ if (tmpLegend.Enabled === false) { return null; }
333
+ return tmpLegend;
130
334
  }
131
335
 
132
336
  /**
@@ -525,6 +729,14 @@ class CustomInputHandler extends libPictSectionInputExtension
525
729
  Object.assign(tmpDataObject, tmpCurrentSolverExpression.DatasetOptions);
526
730
  }
527
731
 
732
+ // Which legend group this series belongs to ("Data", "Limits", …).
733
+ // Carried as a pict-prefixed key so it cannot collide with a Chart.js
734
+ // dataset property.
735
+ if (tmpCurrentSolverExpression.LegendGroup)
736
+ {
737
+ tmpDataObject.pictLegendGroup = tmpCurrentSolverExpression.LegendGroup;
738
+ }
739
+
528
740
  if (tmpParsingConfiguration.ObjectType === 'array')
529
741
  {
530
742
  if (Array.isArray(tmpSolvedDataSet))
@@ -641,6 +853,22 @@ class CustomInputHandler extends libPictSectionInputExtension
641
853
  // would make a single intent ("make this chart taller") into two coupled settings that are wrong
642
854
  // in isolation, so it is derived here. An explicit maintainAspectRatio in the core prototype still
643
855
  // wins -- this only fills in the value the caller did not state.
856
+ // The grouped legend replaces Chart.js's own, which is a single wrapped row
857
+ // of identical swatches -- unreadable once a chart carries a reading, a
858
+ // running average and three pairs of control limits.
859
+ if (this.resolveChartLegendConfiguration(pInput))
860
+ {
861
+ if (typeof (tmpChartConfiguration.options) !== 'object' || tmpChartConfiguration.options === null)
862
+ {
863
+ tmpChartConfiguration.options = {};
864
+ }
865
+ if (typeof (tmpChartConfiguration.options.plugins) !== 'object' || tmpChartConfiguration.options.plugins === null)
866
+ {
867
+ tmpChartConfiguration.options.plugins = {};
868
+ }
869
+ tmpChartConfiguration.options.plugins.legend = Object.assign({}, tmpChartConfiguration.options.plugins.legend, { display: false });
870
+ }
871
+
644
872
  const tmpChartHeight = parseFloat(tmpPictform.ChartHeight);
645
873
  if (isFinite(tmpChartHeight) && (tmpChartHeight > 0))
646
874
  {
@@ -687,6 +915,12 @@ class CustomInputHandler extends libPictSectionInputExtension
687
915
  this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`] = new window.Chart(tmpChartCanvasElement, tmpChartConfiguration);
688
916
  // TODO: Make this invalidation better.
689
917
  this.currentChartDataObjects[`Data-For-${pInput.Macro.RawHTMLID}`] = JSON.stringify(tmpChartConfiguration.data);
918
+
919
+ const tmpLegendConfiguration = this.resolveChartLegendConfiguration(pInput);
920
+ if (tmpLegendConfiguration)
921
+ {
922
+ this.renderChartLegend(pInput.Macro.RawHTMLID, this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`], tmpLegendConfiguration);
923
+ }
690
924
  }
691
925
  }
692
926
 
@@ -782,6 +1016,11 @@ class CustomInputHandler extends libPictSectionInputExtension
782
1016
  {
783
1017
  this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`].data = tmpChartConfiguration.data;
784
1018
  this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`].update();
1019
+ const tmpUpdatedLegendConfiguration = this.resolveChartLegendConfiguration(pInput);
1020
+ if (tmpUpdatedLegendConfiguration)
1021
+ {
1022
+ this.renderChartLegend(pInput.Macro.RawHTMLID, this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`], tmpUpdatedLegendConfiguration);
1023
+ }
785
1024
  this.currentChartDataObjects[`Data-For-${pInput.Macro.RawHTMLID}`] = tmpNewChartDataString;
786
1025
  }
787
1026
  }
@@ -191,6 +191,88 @@ suite('Pict-Provider-Input-Chart', () =>
191
191
  });
192
192
  });
193
193
 
194
+ suite('grouped legend', () =>
195
+ {
196
+ const provider = () => new libChartInput(new libPict(), {});
197
+
198
+ test('ChartLegend is off unless configured, leaving Chart.js\'s own legend alone', () =>
199
+ {
200
+ const tmpProvider = provider();
201
+ Expect(tmpProvider.resolveChartLegendConfiguration({ PictForm: {} })).to.equal(null);
202
+ Expect(tmpProvider.resolveChartLegendConfiguration({ PictForm: { ChartLegend: { Enabled: false } } })).to.equal(null);
203
+ });
204
+
205
+ test('ChartLegend: true is shorthand for a right-hand legend', () =>
206
+ {
207
+ Expect(provider().resolveChartLegendConfiguration({ PictForm: { ChartLegend: true } })).to.deep.equal({ Position: 'right' });
208
+ });
209
+
210
+ test('configuring it disables the built-in legend', () =>
211
+ {
212
+ const tmpPict = new libPict();
213
+ const tmpProvider = new libChartInput(tmpPict, {});
214
+ tmpPict.providers.DynamicSolver = { runSolver: () => [ 1, 2 ] };
215
+ const tmpConfiguration = tmpProvider.getInputChartConfiguration({ }, {
216
+ Name: 'C', Hash: 'C', DataType: 'Object',
217
+ Macro: { RawHTMLID: 'C', InputFullProperties: '', InputChangeHandler: '', ControlAttr: '' },
218
+ PictForm: { InputType: 'Chart', ChartType: 'line', ChartLegend: true, ChartDatasetsSolvers: [ { Label: 'A', DataSolver: 'x' } ] },
219
+ }, {});
220
+ Expect(tmpConfiguration.options.plugins.legend.display).to.equal(false);
221
+ });
222
+
223
+ test('LegendGroup lands on the dataset as pictLegendGroup', () =>
224
+ {
225
+ const tmpPict = new libPict();
226
+ const tmpProvider = new libChartInput(tmpPict, {});
227
+ tmpPict.providers.DynamicSolver = { runSolver: () => [ 1 ] };
228
+ const tmpConfiguration = tmpProvider.getInputChartConfiguration({ }, {
229
+ Name: 'C', Hash: 'C', DataType: 'Object',
230
+ Macro: { RawHTMLID: 'C', InputFullProperties: '', InputChangeHandler: '', ControlAttr: '' },
231
+ PictForm: { InputType: 'Chart', ChartType: 'line', ChartDatasetsSolvers: [
232
+ { Label: 'Reading', DataSolver: 'x' },
233
+ { Label: 'Limit', DataSolver: 'y', LegendGroup: 'Limits' } ] },
234
+ }, {});
235
+ Expect(tmpConfiguration.data.datasets[0].pictLegendGroup).to.equal(undefined);
236
+ Expect(tmpConfiguration.data.datasets[1].pictLegendGroup).to.equal('Limits');
237
+ });
238
+
239
+ test('datasets group by LegendGroup, ungrouped ones falling under Data, in configuration order', () =>
240
+ {
241
+ const tmpChart = { data: { datasets: [
242
+ { label: 'Reading' },
243
+ { label: 'Upper', pictLegendGroup: 'Limits' },
244
+ { label: 'Average' },
245
+ { label: 'Lower', pictLegendGroup: 'Limits' } ] } };
246
+ const tmpGroups = provider()._legendGroups(tmpChart);
247
+ Expect(tmpGroups.map((pGroup) => pGroup.Key)).to.deep.equal([ 'Data', 'Limits' ]);
248
+ Expect(tmpGroups[0].Items.map((pItem) => pItem.Index)).to.deep.equal([ 0, 2 ]);
249
+ Expect(tmpGroups[1].Items.map((pItem) => pItem.Index)).to.deep.equal([ 1, 3 ]);
250
+ });
251
+
252
+ test('the swatch distinguishes solid, dashed, dotted and marker-only series', () =>
253
+ {
254
+ const tmpProvider = provider();
255
+ Expect(tmpProvider._legendSwatchClass({}), 'solid').to.equal('');
256
+ Expect(tmpProvider._legendSwatchClass({ borderDash: [ 6, 4 ] }), 'dashed').to.equal('pict-swatch-dashed');
257
+ Expect(tmpProvider._legendSwatchClass({ borderDash: [ 2, 3 ] }), 'dotted').to.equal('pict-swatch-dotted');
258
+ Expect(tmpProvider._legendSwatchClass({ showLine: false }), 'markers').to.equal('pict-swatch-markers');
259
+ });
260
+
261
+ test('a marker-only series wins over its dash pattern', () =>
262
+ {
263
+ Expect(provider()._legendSwatchClass({ showLine: false, borderDash: [ 6, 4 ] })).to.equal('pict-swatch-markers');
264
+ });
265
+
266
+ test('legend state is per input, so one chart\'s toggles do not move another\'s', () =>
267
+ {
268
+ const tmpProvider = provider();
269
+ tmpProvider.currentChartLegendState['ChartA'] = { Hidden: true, Collapsed: { Limits: true } };
270
+ tmpProvider.currentChartLegendState['ChartB'] = { Hidden: false, Collapsed: {} };
271
+ Expect(tmpProvider.currentChartLegendState['ChartA'].Hidden).to.equal(true);
272
+ Expect(tmpProvider.currentChartLegendState['ChartB'].Hidden).to.equal(false);
273
+ });
274
+ });
275
+
194
276
  suite('template', () =>
195
277
  {
196
278
  test('the chart canvas container carries the ChartHeight min-height', () =>