pict-section-form 1.4.0 → 1.4.2

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.
@@ -113,6 +113,28 @@ module.exports.default_configuration.pict_configuration = {
113
113
  "HiddenValue": "HiddenThree",
114
114
  },
115
115
  ],
116
+ // Read by the Chart section's Address and layered examples
117
+ ChartExamples:
118
+ {
119
+ Labels: ['Spring', 'Summer', 'Autumn', 'Winter'],
120
+ Datasets:
121
+ [
122
+ { label: 'Apples', data: [12, 30, 44, 9] },
123
+ { label: 'Pears', data: [8, 21, 35, 6] }
124
+ ],
125
+ CoreConfiguration:
126
+ {
127
+ type: 'line',
128
+ options: { plugins: { title: { display: true, text: 'Labels, datasets and core configuration read from AppData' } } }
129
+ },
130
+ Harvest:
131
+ [
132
+ { Fruit: 'Apples', Picked: 14, Sold: 11 },
133
+ { Fruit: 'Pears', Picked: 9, Sold: 9 },
134
+ { Fruit: 'Plums', Picked: 6, Sold: 4 },
135
+ { Fruit: 'Figs', Picked: 11, Sold: 7 }
136
+ ]
137
+ },
116
138
  }),
117
139
 
118
140
  DefaultFormManifest: {
@@ -652,6 +674,106 @@ module.exports.default_configuration.pict_configuration = {
652
674
  }
653
675
  },
654
676
 
677
+ "AddressGraphExample": {
678
+ Name: "AddressGraphExample",
679
+ Hash: "AddressGraphExample",
680
+ DataType: "Object",
681
+ PictForm:
682
+ {
683
+ Section: "Chart",
684
+ Group: "SimpleChart",
685
+ Row: 4,
686
+ Width: 6,
687
+ InputType: "Chart",
688
+
689
+ // All three Address keys resolve against the app state
690
+ ChartLabelsAddress: "AppData.ChartExamples.Labels",
691
+ ChartDatasetsAddress: "AppData.ChartExamples.Datasets",
692
+ ChartConfigCorePrototypeAddress: "AppData.ChartExamples.CoreConfiguration"
693
+ }
694
+ },
695
+
696
+ "LayeredGraphExample": {
697
+ Name: "LayeredGraphExample",
698
+ Hash: "LayeredGraphExample",
699
+ DataType: "Object",
700
+ PictForm:
701
+ {
702
+ Section: "Chart",
703
+ Group: "SimpleChart",
704
+ Row: 4,
705
+ Width: 6,
706
+ InputType: "Chart",
707
+
708
+ ChartType: "bar",
709
+ ChartLabelsSolver: `flatten(ChartExamples.Harvest[].Fruit)`,
710
+
711
+ // The Raw datasets come first; the solver datasets are added after them
712
+ ChartDatasetsRaw: [
713
+ {
714
+ type: 'line',
715
+ label: 'Goal',
716
+ data: [10, 10, 10, 10]
717
+ }],
718
+ ChartDatasetsSolvers:
719
+ [
720
+ {
721
+ Label: 'Picked',
722
+ DataSolver: `flatten(ChartExamples.Harvest[].Picked)`
723
+ }
724
+ ],
725
+
726
+ ChartConfigCorePrototypeRaw:
727
+ {
728
+ options: { plugins: { title: { display: true, text: 'Raw Goal line plus a solver Picked series' } } }
729
+ }
730
+ }
731
+ },
732
+
733
+ "LineStyleGraphExample": {
734
+ Name: "LineStyleGraphExample",
735
+ Hash: "LineStyleGraphExample",
736
+ DataType: "Object",
737
+ PictForm:
738
+ {
739
+ Section: "Chart",
740
+ Group: "SimpleChart",
741
+ Row: 5,
742
+ Width: 12,
743
+ InputType: "Chart",
744
+
745
+ ChartType: "line",
746
+ ChartLabelsSolver: `flatten(ChartExamples.Harvest[].Fruit)`,
747
+ ChartDatasetsSolvers:
748
+ [
749
+ {
750
+ Label: 'Picked (chart default curve and points)',
751
+ DataSolver: `flatten(ChartExamples.Harvest[].Picked)`
752
+ },
753
+ {
754
+ Label: 'Sold (Tension 0, PointRadius 0)',
755
+ DataSolver: `flatten(ChartExamples.Harvest[].Sold)`,
756
+ Tension: 0,
757
+ PointRadius: 0
758
+ }
759
+ ],
760
+
761
+ // A curve and large points by default, so a 0 on the dataset is visible
762
+ ChartJSOptionsCorePrototype:
763
+ {
764
+ options: {
765
+ elements: {
766
+ line: { tension: 0.4 },
767
+ point: { radius: 6 }
768
+ },
769
+ plugins: { title: { display: true, text: 'Tension 0 and PointRadius 0 override the chart defaults' } }
770
+ }
771
+ },
772
+
773
+ ChartLegend: true
774
+ }
775
+ },
776
+
655
777
  "UI.StatisticsTabState": {
656
778
  Name: "Statistics Tab State",
657
779
  Hash: "StatisticsTabState",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Pict dynamic forms",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -106,7 +106,7 @@ class PictDynamicFormsInformary extends libPictProvider
106
106
  const tmpFormElements = this.getFormElements(pFormHash);
107
107
 
108
108
  // Optional Filters (so we don't just blindly do the whole form)
109
- const tmpDatum = (pDatum != null) ? false : pDatum;
109
+ const tmpDatum = (pDatum == null) ? false : pDatum;
110
110
  const tmpRecordIndex = (typeof(pRecordIndex) === 'number') ? String(pRecordIndex) : pRecordIndex;
111
111
 
112
112
  // Enumerate the form elements, and put data in them for each address
@@ -9,8 +9,10 @@
9
9
  * indistinguishable from the readings, wrapping into an unreadable block. This
10
10
  * legend is a vertical list, grouped, with each group toggleable as a unit.
11
11
  *
12
- * Everything is themeable through the --theme-color-* tokens; the hardcoded
13
- * values are fallbacks.
12
+ * Everything is themeable through the --theme-color-* tokens (text also through
13
+ * --pict-chart-text-color, which the canvas follows too). Text falls back to the
14
+ * inherited colour, so a host without the tokens still gets a legend that
15
+ * follows its light or dark theme.
14
16
  */
15
17
  const libCSS = /*css*/`
16
18
  .pict-chart-shell { display: flex; align-items: stretch; gap: 0.75rem; width: 100%; }
@@ -19,15 +21,15 @@ const libCSS = /*css*/`
19
21
  .pict-chart-shell .pict-chart-canvas-area { flex: 1 1 auto; min-width: 0; position: relative; }
20
22
 
21
23
  .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; }
24
+ color: var(--pict-chart-text-color, var(--theme-color-text-primary, currentColor)); user-select: none; }
23
25
  .pict-chart-legend-top .pict-chart-legend,
24
26
  .pict-chart-legend-bottom .pict-chart-legend { max-width: none; }
25
27
 
26
28
  .pict-chart-legend-group + .pict-chart-legend-group { margin-top: 0.5rem; }
27
29
  .pict-chart-legend-group-header { display: flex; align-items: center; gap: 0.35rem; cursor: pointer;
28
30
  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
+ color: var(--theme-color-text-muted, currentColor); padding: 0.15rem 0; }
32
+ .pict-chart-legend-group-header:hover { color: var(--theme-color-text-primary, currentColor); }
31
33
  .pict-chart-legend-group-caret { font-size: 0.6rem; transition: transform 0.12s ease; }
32
34
  .pict-chart-legend-group.pict-collapsed .pict-chart-legend-group-caret { transform: rotate(-90deg); }
33
35
  .pict-chart-legend-group.pict-collapsed .pict-chart-legend-items { display: none; }
@@ -61,10 +63,10 @@ const libCSS = /*css*/`
61
63
  transform: translate(-50%, -50%); width: 0.45rem; height: 0.45rem; border-radius: 50%; background: currentColor; }
62
64
 
63
65
  .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);
66
+ font-size: 0.68rem; color: var(--theme-color-text-muted, currentColor);
65
67
  background: none; border: 1px solid var(--theme-color-border-light, #e8ebf0);
66
68
  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);
69
+ .pict-chart-legend-toggle:hover { color: var(--theme-color-text-primary, currentColor);
68
70
  border-color: var(--theme-color-border-strong, #c2c9d2); }
69
71
 
70
72
  /* ---------------------------------------------------------------------------
@@ -131,6 +131,7 @@ class CustomInputHandler extends libPictSectionInputExtension
131
131
  // Legend visibility + collapsed groups, per input hash, so a redraw does not
132
132
  // undo what the user toggled.
133
133
  this.currentChartLegendState = {};
134
+ this.currentChartThemeColors = {};
134
135
 
135
136
  if (this.pict && this.pict.CSSMap && typeof this.pict.CSSMap.addCSS === 'function')
136
137
  {
@@ -344,6 +345,188 @@ class CustomInputHandler extends libPictSectionInputExtension
344
345
  return tmpLegend;
345
346
  }
346
347
 
348
+ /**
349
+ * Resolve the text and grid colours a chart should draw with from the page
350
+ * around its canvas, so the canvas follows the host's light or dark theme the
351
+ * way the surrounding HTML does. `--pict-chart-text-color` and
352
+ * `--pict-chart-grid-color` win when set; otherwise the text colour is the
353
+ * canvas's inherited CSS `color` and the grid is that colour faded.
354
+ *
355
+ * @param {Object} pInput - The PictForm input object.
356
+ * @return {{ Text: string, Grid: string|null }|null} Null when there is no rendered canvas to read.
357
+ */
358
+ resolveChartThemeColors(pInput)
359
+ {
360
+ if ((typeof (window) === 'undefined') || (typeof (window.getComputedStyle) !== 'function') || !pInput || !pInput.Macro)
361
+ {
362
+ return null;
363
+ }
364
+ const tmpCanvasElements = this.pict.ContentAssignment.getElement(`#CANVAS-FOR-${pInput.Macro.RawHTMLID}`);
365
+ if (!Array.isArray(tmpCanvasElements) || (tmpCanvasElements.length < 1))
366
+ {
367
+ return null;
368
+ }
369
+ const tmpStyle = window.getComputedStyle(tmpCanvasElements[0]);
370
+ const tmpText = tmpStyle.getPropertyValue('--pict-chart-text-color').trim() || tmpStyle.color;
371
+ if (!tmpText)
372
+ {
373
+ return null;
374
+ }
375
+ const tmpGrid = tmpStyle.getPropertyValue('--pict-chart-grid-color').trim() || this._fadeChartColor(tmpText, 0.15);
376
+ return { Text: tmpText, Grid: tmpGrid };
377
+ }
378
+
379
+ /**
380
+ * @param {string} pColor - A computed `rgb()` / `rgba()` colour.
381
+ * @param {number} pAlpha - The opacity to give it.
382
+ * @return {string|null} The faded colour, or null when the colour is in another notation.
383
+ */
384
+ _fadeChartColor(pColor, pAlpha)
385
+ {
386
+ const tmpMatch = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(pColor);
387
+ if (!tmpMatch)
388
+ {
389
+ return null;
390
+ }
391
+ return `rgba(${tmpMatch[1]}, ${tmpMatch[2]}, ${tmpMatch[3]}, ${pAlpha})`;
392
+ }
393
+
394
+ /**
395
+ * Apply theme colours to a drawn chart, filling only the colour options the
396
+ * manifest left unset, so an explicit colour always wins. Chart.js takes
397
+ * tick, grid and title colours from its global defaults rather than the
398
+ * chart's own `color`, so every scale the chart drew is coloured by id.
399
+ *
400
+ * @param {Object} pChart - The Chart.js instance.
401
+ * @param {Object} pManifestOptions - The chart options as built from the manifest, before Chart.js filled in its defaults.
402
+ * @param {{ Text: string, Grid: string|null }|null} pColors - From resolveChartThemeColors.
403
+ * @return {boolean} True when a colour changed and the chart was updated.
404
+ */
405
+ applyChartThemeColors(pChart, pManifestOptions, pColors)
406
+ {
407
+ if (!pChart || (typeof (pChart.options) !== 'object') || !pColors)
408
+ {
409
+ return false;
410
+ }
411
+ const tmpManifestOptions = (typeof (pManifestOptions) === 'object' && pManifestOptions !== null) ? pManifestOptions : {};
412
+ let tmpChanged = false;
413
+ const fSetUnlessExplicit = (pPath, pValue) =>
414
+ {
415
+ if (!pValue)
416
+ {
417
+ return;
418
+ }
419
+ if (typeof (this.pict.manifest.getValueByHash(tmpManifestOptions, pPath)) !== 'undefined')
420
+ {
421
+ return;
422
+ }
423
+ const tmpParts = pPath.split('.');
424
+ let tmpTarget = pChart.options;
425
+ for (let i = 0; i < tmpParts.length - 1; i++)
426
+ {
427
+ if ((typeof (tmpTarget[tmpParts[i]]) !== 'object') || (tmpTarget[tmpParts[i]] === null))
428
+ {
429
+ tmpTarget[tmpParts[i]] = {};
430
+ }
431
+ tmpTarget = tmpTarget[tmpParts[i]];
432
+ }
433
+ const tmpKey = tmpParts[tmpParts.length - 1];
434
+ if (tmpTarget[tmpKey] !== pValue)
435
+ {
436
+ tmpTarget[tmpKey] = pValue;
437
+ tmpChanged = true;
438
+ }
439
+ };
440
+
441
+ fSetUnlessExplicit('color', pColors.Text);
442
+ fSetUnlessExplicit('plugins.title.color', pColors.Text);
443
+ fSetUnlessExplicit('plugins.subtitle.color', pColors.Text);
444
+
445
+ const tmpScales = (typeof (pChart.scales) === 'object' && pChart.scales !== null) ? pChart.scales : {};
446
+ const tmpScaleIDs = Object.keys(tmpScales);
447
+ for (let i = 0; i < tmpScaleIDs.length; i++)
448
+ {
449
+ const tmpScaleAddress = `scales.${tmpScaleIDs[i]}`;
450
+ fSetUnlessExplicit(`${tmpScaleAddress}.ticks.color`, pColors.Text);
451
+ fSetUnlessExplicit(`${tmpScaleAddress}.title.color`, pColors.Text);
452
+ fSetUnlessExplicit(`${tmpScaleAddress}.grid.color`, pColors.Grid);
453
+ fSetUnlessExplicit(`${tmpScaleAddress}.border.color`, pColors.Grid);
454
+ const tmpScaleOptions = tmpScales[tmpScaleIDs[i]] && tmpScales[tmpScaleIDs[i]].options;
455
+ if (tmpScaleOptions && tmpScaleOptions.pointLabels)
456
+ {
457
+ fSetUnlessExplicit(`${tmpScaleAddress}.pointLabels.color`, pColors.Text);
458
+ fSetUnlessExplicit(`${tmpScaleAddress}.angleLines.color`, pColors.Grid);
459
+ // Radial tick labels sit on a white backdrop by default, which hides light text
460
+ fSetUnlessExplicit(`${tmpScaleAddress}.ticks.backdropColor`, 'transparent');
461
+ }
462
+ }
463
+
464
+ if (tmpChanged && (typeof (pChart.update) === 'function'))
465
+ {
466
+ pChart.update('none');
467
+ }
468
+ return tmpChanged;
469
+ }
470
+
471
+ /**
472
+ * Re-read the theme colours around a chart and apply them when they differ
473
+ * from the last ones applied to it (or always, when forced for a new chart).
474
+ *
475
+ * @param {Object} pInput - The PictForm input object.
476
+ * @param {Object} pChart - The Chart.js instance.
477
+ * @param {Object} pManifestOptions - The chart options as built from the manifest.
478
+ * @param {boolean} [pForce] - Apply even if the colours have not changed.
479
+ */
480
+ refreshChartThemeColors(pInput, pChart, pManifestOptions, pForce)
481
+ {
482
+ const tmpColors = this.resolveChartThemeColors(pInput);
483
+ if (!tmpColors)
484
+ {
485
+ return;
486
+ }
487
+ const tmpKey = `Theme-For-${pInput.Macro.RawHTMLID}`;
488
+ const tmpSignature = JSON.stringify(tmpColors);
489
+ if (!pForce && (this.currentChartThemeColors[tmpKey] === tmpSignature))
490
+ {
491
+ return;
492
+ }
493
+ this.applyChartThemeColors(pChart, pManifestOptions, tmpColors);
494
+ this.currentChartThemeColors[tmpKey] = tmpSignature;
495
+ }
496
+
497
+ /**
498
+ * Copy the arrays and plain objects of a chart configuration fragment, so the
499
+ * parsing steps can merge into it without writing back into the manifest or
500
+ * application state it was read from. Anything else (functions such as
501
+ * Chart.js callbacks, class instances) is carried across by reference.
502
+ *
503
+ * @param {any} pValue - The configuration fragment.
504
+ * @return {any} The copy.
505
+ */
506
+ _cloneChartConfiguration(pValue)
507
+ {
508
+ if (Array.isArray(pValue))
509
+ {
510
+ return pValue.map((pItem) => this._cloneChartConfiguration(pItem));
511
+ }
512
+ if ((pValue === null) || (typeof (pValue) !== 'object'))
513
+ {
514
+ return pValue;
515
+ }
516
+ const tmpPrototype = Object.getPrototypeOf(pValue);
517
+ if ((tmpPrototype !== Object.prototype) && (tmpPrototype !== null))
518
+ {
519
+ return pValue;
520
+ }
521
+ const tmpCopy = {};
522
+ const tmpKeys = Object.keys(pValue);
523
+ for (let i = 0; i < tmpKeys.length; i++)
524
+ {
525
+ tmpCopy[tmpKeys[i]] = this._cloneChartConfiguration(pValue[tmpKeys[i]]);
526
+ }
527
+ return tmpCopy;
528
+ }
529
+
347
530
  /**
348
531
  *
349
532
  * @param {Object} pInput - The PictForm input object
@@ -384,25 +567,26 @@ class CustomInputHandler extends libPictSectionInputExtension
384
567
  if (typeof (tmpInputCustomConfiguration) === 'object')
385
568
  {
386
569
  // Merge the custom configuration into the base configuration
387
- tmpParsingConfiguration = Object.assign(tmpParsingConfiguration, tmpInputCustomConfiguration);
570
+ tmpParsingConfiguration = Object.assign({}, tmpParsingConfiguration, tmpInputCustomConfiguration);
388
571
  }
389
572
 
390
- // Get existing data
391
573
  let tmpExistingData;
392
- if (!tmpParsingConfiguration.AddressInObject || (tmpParsingConfiguration.AddressInObject == ''))
393
- {
394
- tmpExistingData = tmpChartConfiguration;
395
- }
396
- else
397
- {
398
- tmpExistingData = this.pict.manifest.getValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject);
399
- }
400
574
 
401
575
  // 2. Enumerate through each step and apply them consistently
402
576
  for (let i = 0; i < tmpParsingConfiguration.Steps.length; i++)
403
577
  {
404
578
  let tmpCurrentStep = tmpParsingConfiguration.Steps[i];
405
579
 
580
+ // Get existing data -- what the earlier steps left, so a merging step layers onto them
581
+ if (!tmpParsingConfiguration.AddressInObject || (tmpParsingConfiguration.AddressInObject == ''))
582
+ {
583
+ tmpExistingData = tmpChartConfiguration;
584
+ }
585
+ else
586
+ {
587
+ tmpExistingData = this.pict.manifest.getValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject);
588
+ }
589
+
406
590
  switch (tmpCurrentStep.Method)
407
591
  {
408
592
  case 'Initialize':
@@ -440,7 +624,7 @@ class CustomInputHandler extends libPictSectionInputExtension
440
624
  }
441
625
 
442
626
  // Get the raw data from the input
443
- let tmpRawData = this.pict.manifest.getValueByHash(tmpInput, tmpCurrentStep.InputProperty);
627
+ let tmpRawData = this._cloneChartConfiguration(this.pict.manifest.getValueByHash(tmpInput, tmpCurrentStep.InputProperty));
444
628
  let tmpRawDataType = typeof(tmpRawData);
445
629
 
446
630
  // We only support objects as configuration
@@ -521,7 +705,7 @@ class CustomInputHandler extends libPictSectionInputExtension
521
705
  break;
522
706
  }
523
707
 
524
- let tmpPotentialConfigurationObject = this.pict.resolveStateFromAddress(tmpAddress, pInput);
708
+ let tmpPotentialConfigurationObject = this._cloneChartConfiguration(this.pict.resolveStateFromAddress(tmpAddress, pInput));
525
709
 
526
710
  if (typeof (tmpPotentialConfigurationObject) !== 'object')
527
711
  {
@@ -530,7 +714,7 @@ class CustomInputHandler extends libPictSectionInputExtension
530
714
 
531
715
  if (tmpParsingConfiguration.ObjectType === 'array')
532
716
  {
533
- if (Array.isArray(tmpRawData))
717
+ if (Array.isArray(tmpPotentialConfigurationObject))
534
718
  {
535
719
  if (tmpCurrentStep.Merge)
536
720
  {
@@ -540,13 +724,13 @@ class CustomInputHandler extends libPictSectionInputExtension
540
724
  tmpExistingData = [];
541
725
  }
542
726
  // Merge in the arrays
543
- let tmpMergedData = tmpExistingData.concat(tmpRawData);
727
+ let tmpMergedData = tmpExistingData.concat(tmpPotentialConfigurationObject);
544
728
  this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpMergedData);
545
729
  }
546
730
  else
547
731
  {
548
732
  // Just set the value
549
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
733
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpPotentialConfigurationObject);
550
734
  }
551
735
  }
552
736
  }
@@ -559,11 +743,11 @@ class CustomInputHandler extends libPictSectionInputExtension
559
743
  // This is the "root" object, so we need to merge or set directly
560
744
  if (tmpCurrentStep.Merge)
561
745
  {
562
- tmpChartConfiguration = Object.assign(tmpChartConfiguration, tmpRawData);
746
+ tmpChartConfiguration = Object.assign(tmpChartConfiguration, tmpPotentialConfigurationObject);
563
747
  }
564
748
  else
565
749
  {
566
- tmpChartConfiguration = tmpRawData;
750
+ tmpChartConfiguration = tmpPotentialConfigurationObject;
567
751
  }
568
752
  }
569
753
  else
@@ -575,20 +759,20 @@ class CustomInputHandler extends libPictSectionInputExtension
575
759
  if (tmpCurrentStep.Merge)
576
760
  {
577
761
  // Merge the objects
578
- let tmpMergedData = Object.assign(tmpExistingData, tmpRawData);
762
+ let tmpMergedData = Object.assign(tmpExistingData, tmpPotentialConfigurationObject);
579
763
  this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpMergedData);
580
764
  }
581
765
  else
582
766
  {
583
767
  // Just set the value
584
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
768
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpPotentialConfigurationObject);
585
769
  }
586
770
  }
587
771
  }
588
772
  else
589
773
  {
590
774
  // Just set the value?
591
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
775
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpPotentialConfigurationObject);
592
776
  }
593
777
  }
594
778
  break;
@@ -655,14 +839,14 @@ class CustomInputHandler extends libPictSectionInputExtension
655
839
  else
656
840
  {
657
841
  // Just set the value
658
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
842
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpSolvedConfiguration);
659
843
  }
660
844
  }
661
845
  }
662
846
  else
663
847
  {
664
848
  // Just set the value?
665
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
849
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpSolvedConfiguration);
666
850
  }
667
851
  }
668
852
  break;
@@ -712,13 +896,13 @@ class CustomInputHandler extends libPictSectionInputExtension
712
896
  }
713
897
 
714
898
  // Add in a custom Tension
715
- if (tmpCurrentSolverExpression.Tension)
899
+ if ((tmpCurrentSolverExpression.Tension !== undefined) && (tmpCurrentSolverExpression.Tension !== null))
716
900
  {
717
901
  tmpDataObject.tension = tmpCurrentSolverExpression.Tension;
718
902
  }
719
903
 
720
904
  // Add in a custom pointRadius
721
- if (tmpCurrentSolverExpression.PointRadius)
905
+ if ((tmpCurrentSolverExpression.PointRadius !== undefined) && (tmpCurrentSolverExpression.PointRadius !== null))
722
906
  {
723
907
  tmpDataObject.pointRadius = tmpCurrentSolverExpression.PointRadius;
724
908
  }
@@ -799,14 +983,14 @@ class CustomInputHandler extends libPictSectionInputExtension
799
983
  else
800
984
  {
801
985
  // Just set the value
802
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
986
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpSolvedDataSet);
803
987
  }
804
988
  }
805
989
  }
806
990
  else
807
991
  {
808
992
  // Just set the value?
809
- this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpRawData);
993
+ this.pict.manifest.setValueByHash(tmpChartConfiguration, tmpParsingConfiguration.AddressInObject, tmpSolvedDataSet);
810
994
  }
811
995
  }
812
996
  }
@@ -828,7 +1012,7 @@ class CustomInputHandler extends libPictSectionInputExtension
828
1012
 
829
1013
  let tmpPictform = pInput.PictForm;
830
1014
 
831
- let tmpChartConfiguration = (typeof (tmpPictform.ChartJSOptionsCorePrototype) === 'object') ? tmpPictform.ChartJSOptionsCorePrototype : {};
1015
+ let tmpChartConfiguration = (typeof (tmpPictform.ChartJSOptionsCorePrototype) === 'object') ? this._cloneChartConfiguration(tmpPictform.ChartJSOptionsCorePrototype) : {};
832
1016
 
833
1017
  this.applyInputParsingConfiguration(pInput, tmpChartConfiguration, this.defaultCoreParsingConfiguration, 'PictForm.ChartConfigCoreParsingConfigurationOverride');
834
1018
  if (!('type' in tmpChartConfiguration))
@@ -923,9 +1107,12 @@ class CustomInputHandler extends libPictSectionInputExtension
923
1107
  }
924
1108
  else
925
1109
  {
1110
+ // Chart.js writes its resolved defaults back into the options it is given
1111
+ const tmpManifestOptions = this._cloneChartConfiguration(tmpChartConfiguration.options || {});
926
1112
  this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`] = new window.Chart(tmpChartCanvasElement, tmpChartConfiguration);
927
1113
  // TODO: Make this invalidation better.
928
1114
  this.currentChartDataObjects[`Data-For-${pInput.Macro.RawHTMLID}`] = JSON.stringify(tmpChartConfiguration.data);
1115
+ this.refreshChartThemeColors(pInput, this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`], tmpManifestOptions, true);
929
1116
 
930
1117
  const tmpLegendConfiguration = this.resolveChartLegendConfiguration(pInput);
931
1118
  if (tmpLegendConfiguration)
@@ -1034,6 +1221,7 @@ class CustomInputHandler extends libPictSectionInputExtension
1034
1221
  }
1035
1222
  this.currentChartDataObjects[`Data-For-${pInput.Macro.RawHTMLID}`] = tmpNewChartDataString;
1036
1223
  }
1224
+ this.refreshChartThemeColors(pInput, this.currentChartObjects[`Object-For-${pInput.Macro.RawHTMLID}`], tmpChartConfiguration.options);
1037
1225
  }
1038
1226
  return super.onDataMarshalToForm(pView, pGroup, pRow, pInput, pValue, pHTMLSelector, pTransactionGUID);
1039
1227
  }
@@ -107,5 +107,87 @@ suite(
107
107
  );
108
108
  }
109
109
  );
110
+
111
+ suite(
112
+ 'marshalFormToData honours the datum and record index filters',
113
+ () =>
114
+ {
115
+ const buildElement = (pAttributes) =>
116
+ {
117
+ return { getAttribute: (pName) => (pName in pAttributes ? pAttributes[pName] : null) };
118
+ };
119
+
120
+ // A form with two plain inputs and a two-row recordset; the browser holds a value for each.
121
+ const buildHarness = () =>
122
+ {
123
+ const tmpPict = new libPict({ Product: 'MockInformary', ProductVersion: '1.0.0' });
124
+ tmpPict.addProviderSingleton('Informary', libInformary.default_configuration, libInformary);
125
+ const tmpInformary = tmpPict.providers.Informary;
126
+ const tmpElements = [
127
+ buildElement({ 'data-i-datum': 'Title' }),
128
+ buildElement({ 'data-i-datum': 'Author' }),
129
+ buildElement({ 'data-i-datum': 'Price', 'data-i-container': 'Editions', 'data-i-index': '0' }),
130
+ buildElement({ 'data-i-datum': 'Price', 'data-i-container': 'Editions', 'data-i-index': '1' })
131
+ ];
132
+ const tmpBrowserValues = {};
133
+ tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Title')] = 'Browser Title';
134
+ tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Author')] = 'Browser Author';
135
+ tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Price', 'Editions', '0')] = 'Browser Price 0';
136
+ tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Price', 'Editions', '1')] = 'Browser Price 1';
137
+ tmpInformary.getFormElements = () => tmpElements;
138
+ tmpPict.ContentAssignment.readContent = (pAddress) => tmpBrowserValues[pAddress];
139
+ const tmpWrites = [];
140
+ const tmpManifest = { setValueAtAddress: (pData, pAddress, pValue) => { tmpWrites.push(pAddress); pData[pAddress] = pValue; } };
141
+ return { informary: tmpInformary, manifest: tmpManifest, writes: tmpWrites };
142
+ };
143
+
144
+ test(
145
+ 'with no datum, every element is copied back',
146
+ (fDone) =>
147
+ {
148
+ const tmpHarness = buildHarness();
149
+ tmpHarness.informary.marshalFormToData({}, 'Shelf', tmpHarness.manifest);
150
+ Expect(tmpHarness.writes).to.deep.equal([ 'Title', 'Author', 'Editions[0].Price', 'Editions[1].Price' ]);
151
+ fDone();
152
+ }
153
+ );
154
+
155
+ test(
156
+ 'with a datum, only that element is copied back (a stale value elsewhere in the form is left alone)',
157
+ (fDone) =>
158
+ {
159
+ const tmpHarness = buildHarness();
160
+ const tmpData = { Author: 'Value set by a solver' };
161
+ tmpHarness.informary.marshalFormToData(tmpData, 'Shelf', tmpHarness.manifest, 'Title');
162
+ Expect(tmpHarness.writes).to.deep.equal([ 'Title' ]);
163
+ Expect(tmpData.Title).to.equal('Browser Title');
164
+ Expect(tmpData.Author).to.equal('Value set by a solver');
165
+ fDone();
166
+ }
167
+ );
168
+
169
+ test(
170
+ 'with a datum and a record index, only that row of that column is copied back',
171
+ (fDone) =>
172
+ {
173
+ const tmpHarness = buildHarness();
174
+ tmpHarness.informary.marshalFormToData({}, 'Shelf', tmpHarness.manifest, 'Price', 1);
175
+ Expect(tmpHarness.writes).to.deep.equal([ 'Editions[1].Price' ]);
176
+ fDone();
177
+ }
178
+ );
179
+
180
+ test(
181
+ 'a null datum is treated as no filter',
182
+ (fDone) =>
183
+ {
184
+ const tmpHarness = buildHarness();
185
+ tmpHarness.informary.marshalFormToData({}, 'Shelf', tmpHarness.manifest, null);
186
+ Expect(tmpHarness.writes.length).to.equal(4);
187
+ fDone();
188
+ }
189
+ );
190
+ }
191
+ );
110
192
  }
111
193
  );
@@ -191,6 +191,335 @@ suite('Pict-Provider-Input-Chart', () =>
191
191
  });
192
192
  });
193
193
 
194
+ suite('parsing steps', () =>
195
+ {
196
+ const buildChart = (pPictForm) =>
197
+ {
198
+ const tmpPict = new libPict();
199
+ const tmpProvider = new libChartInput(tmpPict, {});
200
+ tmpPict.providers.DynamicSolver = { runSolver: () => [ 1, 2, 3 ] };
201
+ const tmpInput =
202
+ {
203
+ Name: 'C', Hash: 'C', DataType: 'Object',
204
+ Macro: { RawHTMLID: 'C-input', InputFullProperties: '', InputChangeHandler: '', ControlAttr: '' },
205
+ PictForm: Object.assign({ InputType: 'Chart', ChartType: 'line' }, pPictForm),
206
+ };
207
+ return { Pict: tmpPict, Provider: tmpProvider, Input: tmpInput, resolve: () => tmpProvider.getInputChartConfiguration({ }, tmpInput, {}) };
208
+ };
209
+
210
+ test('ChartLabelsAddress reads the labels from application state', () =>
211
+ {
212
+ const tmpChart = buildChart({ ChartLabelsAddress: 'AppData.Shelf.Labels' });
213
+ tmpChart.Pict.AppData.Shelf = { Labels: [ 'Fiction', 'Poetry' ] };
214
+ Expect(tmpChart.resolve().data.labels).to.deep.equal([ 'Fiction', 'Poetry' ]);
215
+ });
216
+
217
+ test('ChartDatasetsAddress reads the datasets from application state', () =>
218
+ {
219
+ const tmpChart = buildChart({ ChartDatasetsAddress: 'AppData.Shelf.Datasets' });
220
+ tmpChart.Pict.AppData.Shelf = { Datasets: [ { label: 'Copies', data: [ 4, 7 ] } ] };
221
+ Expect(tmpChart.resolve().data.datasets).to.deep.equal([ { label: 'Copies', data: [ 4, 7 ] } ]);
222
+ });
223
+
224
+ test('ChartConfigCorePrototypeAddress merges a core configuration from application state', () =>
225
+ {
226
+ const tmpChart = buildChart({ ChartConfigCorePrototypeAddress: 'AppData.Shelf.Core' });
227
+ tmpChart.Pict.AppData.Shelf = { Core: { type: 'radar', options: { animation: false } } };
228
+ const tmpConfiguration = tmpChart.resolve();
229
+ Expect(tmpConfiguration.type).to.equal('radar');
230
+ Expect(tmpConfiguration.options.animation).to.equal(false);
231
+ });
232
+
233
+ test('solver datasets are added after the Raw datasets rather than replacing them', () =>
234
+ {
235
+ const tmpChart = buildChart(
236
+ {
237
+ ChartDatasetsRaw: [ { label: 'Target', data: [ 5, 5, 5 ] } ],
238
+ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ],
239
+ });
240
+ Expect(tmpChart.resolve().data.datasets.map((pDataset) => pDataset.label)).to.deep.equal([ 'Target', 'Sold' ]);
241
+ });
242
+
243
+ test('solver datasets are added after the Address datasets rather than replacing them', () =>
244
+ {
245
+ const tmpChart = buildChart(
246
+ {
247
+ ChartDatasetsAddress: 'AppData.Shelf.Datasets',
248
+ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ],
249
+ });
250
+ tmpChart.Pict.AppData.Shelf = { Datasets: [ { label: 'Target', data: [ 5, 5, 5 ] } ] };
251
+ Expect(tmpChart.resolve().data.datasets.map((pDataset) => pDataset.label)).to.deep.equal([ 'Target', 'Sold' ]);
252
+ });
253
+
254
+ test('resolving again does not pile datasets onto ChartJSOptionsCorePrototype', () =>
255
+ {
256
+ // Every data refresh resolves the configuration again; the solver
257
+ // datasets were pushed onto the manifest's own object each time.
258
+ const tmpChart = buildChart(
259
+ {
260
+ ChartJSOptionsCorePrototype: { type: 'bar' },
261
+ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ],
262
+ });
263
+ tmpChart.resolve();
264
+ tmpChart.resolve();
265
+ Expect(tmpChart.resolve().data.datasets.length).to.equal(1);
266
+ Expect(tmpChart.Input.PictForm.ChartJSOptionsCorePrototype).to.deep.equal({ type: 'bar' });
267
+ });
268
+
269
+ test('resolving again does not pile datasets onto ChartConfigCorePrototypeRaw', () =>
270
+ {
271
+ const tmpChart = buildChart(
272
+ {
273
+ ChartConfigCorePrototypeRaw: { data: { datasets: [ { label: 'Target', data: [ 5 ] } ] } },
274
+ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ],
275
+ });
276
+ tmpChart.resolve();
277
+ tmpChart.resolve();
278
+ Expect(tmpChart.resolve().data.datasets.map((pDataset) => pDataset.label)).to.deep.equal([ 'Target', 'Sold' ]);
279
+ Expect(tmpChart.Input.PictForm.ChartConfigCorePrototypeRaw).to.deep.equal({ data: { datasets: [ { label: 'Target', data: [ 5 ] } ] } });
280
+ });
281
+
282
+ test('Raw and Address sources are left unmodified by the solver step', () =>
283
+ {
284
+ const tmpRawChart = buildChart(
285
+ {
286
+ ChartDatasetsRaw: [ { label: 'Target', data: [ 5, '' ] } ],
287
+ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ],
288
+ });
289
+ tmpRawChart.resolve();
290
+ Expect(tmpRawChart.Input.PictForm.ChartDatasetsRaw).to.deep.equal([ { label: 'Target', data: [ 5, '' ] } ]);
291
+
292
+ const tmpAddressChart = buildChart(
293
+ {
294
+ ChartDatasetsAddress: 'AppData.Shelf.Datasets',
295
+ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ],
296
+ });
297
+ tmpAddressChart.Pict.AppData.Shelf = { Datasets: [ { label: 'Target', data: [ 5 ] } ] };
298
+ tmpAddressChart.resolve();
299
+ Expect(tmpAddressChart.Pict.AppData.Shelf.Datasets).to.deep.equal([ { label: 'Target', data: [ 5 ] } ]);
300
+ });
301
+
302
+ test('function-valued options in a prototype are kept, not dropped by the copy', () =>
303
+ {
304
+ const fLabel = () => 'label';
305
+ const tmpChart = buildChart({ ChartJSOptionsCorePrototype: { options: { plugins: { tooltip: { callbacks: { label: fLabel } } } } } });
306
+ Expect(tmpChart.resolve().options.plugins.tooltip.callbacks.label).to.equal(fLabel);
307
+ });
308
+
309
+ test('a parsing configuration override applies to its own input only', () =>
310
+ {
311
+ const tmpPict = new libPict();
312
+ const tmpProvider = new libChartInput(tmpPict, {});
313
+ const tmpInput = (pHash, pPictForm) => (
314
+ {
315
+ Name: pHash, Hash: pHash, DataType: 'Object',
316
+ Macro: { RawHTMLID: `${pHash}-input`, InputFullProperties: '', InputChangeHandler: '', ControlAttr: '' },
317
+ PictForm: Object.assign({ InputType: 'Chart', ChartType: 'line' }, pPictForm),
318
+ });
319
+ tmpProvider.getInputChartConfiguration({ }, tmpInput('First',
320
+ {
321
+ ChartLabelsRaw: [ 'a' ],
322
+ ChartLabelsParsingConfigurationOverride: { AddressInObject: 'data.xLabels' },
323
+ }), {});
324
+ const tmpSecond = tmpProvider.getInputChartConfiguration({ }, tmpInput('Second', { ChartLabelsRaw: [ 'b' ] }), {});
325
+ Expect(tmpSecond.data.labels).to.deep.equal([ 'b' ]);
326
+ Expect(tmpSecond.data).to.not.have.property('xLabels');
327
+ Expect(tmpProvider.defaultLabelParsingConfiguration.AddressInObject).to.equal('data.labels');
328
+ });
329
+
330
+ test('a Tension or PointRadius of 0 reaches the dataset', () =>
331
+ {
332
+ const tmpChart = buildChart({ ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x', Tension: 0, PointRadius: 0 } ] });
333
+ const tmpDataset = tmpChart.resolve().data.datasets[0];
334
+ Expect(tmpDataset.tension).to.equal(0);
335
+ Expect(tmpDataset.pointRadius).to.equal(0);
336
+ });
337
+ });
338
+
339
+ suite('theme colours', () =>
340
+ {
341
+ // The jsdom used here computes neither inherited colours nor custom
342
+ // properties, so the computed style a browser would report is stubbed.
343
+ const stubComputedStyle = (pValues) =>
344
+ {
345
+ const fOriginal = window.getComputedStyle;
346
+ window.getComputedStyle = () => (
347
+ {
348
+ color: pValues.color || '',
349
+ getPropertyValue: (pName) => pValues[pName] || '',
350
+ });
351
+ return () => { window.getComputedStyle = fOriginal; };
352
+ };
353
+
354
+ const addCanvas = (pRawHTMLID) =>
355
+ {
356
+ const tmpCanvas = document.createElement('canvas');
357
+ tmpCanvas.id = `CANVAS-FOR-${pRawHTMLID}`;
358
+ document.body.appendChild(tmpCanvas);
359
+ return tmpCanvas;
360
+ };
361
+
362
+ const fakeChart = (pScales) => (
363
+ {
364
+ options: {},
365
+ scales: pScales || { x: { options: {} }, y: { options: {} } },
366
+ updates: 0,
367
+ update() { this.updates++; },
368
+ });
369
+
370
+ test('the text colour is the canvas\'s inherited CSS color, and the grid is that colour faded', () =>
371
+ {
372
+ const tmpProvider = new libChartInput(new libPict(), {});
373
+ addCanvas('ThemeRead-input');
374
+ const fRestore = stubComputedStyle({ color: 'rgb(230, 231, 232)' });
375
+ try
376
+ {
377
+ Expect(tmpProvider.resolveChartThemeColors({ Macro: { RawHTMLID: 'ThemeRead-input' } }))
378
+ .to.deep.equal({ Text: 'rgb(230, 231, 232)', Grid: 'rgba(230, 231, 232, 0.15)' });
379
+ }
380
+ finally
381
+ {
382
+ fRestore();
383
+ }
384
+ });
385
+
386
+ test('--pict-chart-text-color and --pict-chart-grid-color win over the inherited colour', () =>
387
+ {
388
+ const tmpProvider = new libChartInput(new libPict(), {});
389
+ addCanvas('ThemeVariables-input');
390
+ const fRestore = stubComputedStyle({ 'color': 'rgb(0, 0, 0)', '--pict-chart-text-color': ' #eeeeee', '--pict-chart-grid-color': '#333333 ' });
391
+ try
392
+ {
393
+ Expect(tmpProvider.resolveChartThemeColors({ Macro: { RawHTMLID: 'ThemeVariables-input' } }))
394
+ .to.deep.equal({ Text: '#eeeeee', Grid: '#333333' });
395
+ }
396
+ finally
397
+ {
398
+ fRestore();
399
+ }
400
+ });
401
+
402
+ test('a text colour that is not rgb() still themes the text and leaves the grid to Chart.js', () =>
403
+ {
404
+ const tmpProvider = new libChartInput(new libPict(), {});
405
+ addCanvas('ThemeNotation-input');
406
+ const fRestore = stubComputedStyle({ color: 'oklch(0.9 0 0)' });
407
+ try
408
+ {
409
+ Expect(tmpProvider.resolveChartThemeColors({ Macro: { RawHTMLID: 'ThemeNotation-input' } }))
410
+ .to.deep.equal({ Text: 'oklch(0.9 0 0)', Grid: null });
411
+ }
412
+ finally
413
+ {
414
+ fRestore();
415
+ }
416
+ });
417
+
418
+ test('an input with no rendered canvas resolves to no colours', () =>
419
+ {
420
+ const tmpProvider = new libChartInput(new libPict(), {});
421
+ Expect(tmpProvider.resolveChartThemeColors({ Macro: { RawHTMLID: 'NeverRendered-input' } })).to.equal(null);
422
+ });
423
+
424
+ test('every scale the chart drew is coloured, along with the chart, title and subtitle text', () =>
425
+ {
426
+ const tmpProvider = new libChartInput(new libPict(), {});
427
+ const tmpChart = fakeChart();
428
+ const tmpChanged = tmpProvider.applyChartThemeColors(tmpChart, {}, { Text: '#eee', Grid: 'rgba(238, 238, 238, 0.15)' });
429
+ Expect(tmpChanged).to.equal(true);
430
+ Expect(tmpChart.updates).to.equal(1);
431
+ Expect(tmpChart.options.color).to.equal('#eee');
432
+ Expect(tmpChart.options.plugins.title.color).to.equal('#eee');
433
+ Expect(tmpChart.options.plugins.subtitle.color).to.equal('#eee');
434
+ for (const tmpID of [ 'x', 'y' ])
435
+ {
436
+ Expect(tmpChart.options.scales[tmpID].ticks.color, tmpID).to.equal('#eee');
437
+ Expect(tmpChart.options.scales[tmpID].title.color, tmpID).to.equal('#eee');
438
+ Expect(tmpChart.options.scales[tmpID].grid.color, tmpID).to.equal('rgba(238, 238, 238, 0.15)');
439
+ Expect(tmpChart.options.scales[tmpID].border.color, tmpID).to.equal('rgba(238, 238, 238, 0.15)');
440
+ }
441
+ Expect(tmpChart.options.scales.x).to.not.have.property('pointLabels');
442
+ });
443
+
444
+ test('an explicit colour in the manifest wins over the theme', () =>
445
+ {
446
+ const tmpProvider = new libChartInput(new libPict(), {});
447
+ const tmpChart = fakeChart();
448
+ tmpChart.options = { scales: { y: { ticks: { color: 'green' } } }, plugins: { title: { color: 'purple' } } };
449
+ tmpProvider.applyChartThemeColors(tmpChart,
450
+ { scales: { y: { ticks: { color: 'green' } } }, plugins: { title: { color: 'purple' } } },
451
+ { Text: '#eee', Grid: null });
452
+ Expect(tmpChart.options.scales.y.ticks.color).to.equal('green');
453
+ Expect(tmpChart.options.plugins.title.color).to.equal('purple');
454
+ Expect(tmpChart.options.scales.x.ticks.color).to.equal('#eee');
455
+ Expect(tmpChart.options.scales.x).to.not.have.property('grid');
456
+ });
457
+
458
+ test('a radial scale also gets point labels, angle lines and a transparent tick backdrop', () =>
459
+ {
460
+ const tmpProvider = new libChartInput(new libPict(), {});
461
+ const tmpChart = fakeChart({ r: { options: { pointLabels: {} } } });
462
+ tmpProvider.applyChartThemeColors(tmpChart, {}, { Text: '#eee', Grid: '#444' });
463
+ Expect(tmpChart.options.scales.r.pointLabels.color).to.equal('#eee');
464
+ Expect(tmpChart.options.scales.r.angleLines.color).to.equal('#444');
465
+ Expect(tmpChart.options.scales.r.ticks.backdropColor).to.equal('transparent');
466
+ });
467
+
468
+ test('applying the same colours again changes nothing and does not redraw', () =>
469
+ {
470
+ const tmpProvider = new libChartInput(new libPict(), {});
471
+ const tmpChart = fakeChart();
472
+ const tmpColors = { Text: '#eee', Grid: '#444' };
473
+ tmpProvider.applyChartThemeColors(tmpChart, {}, tmpColors);
474
+ Expect(tmpProvider.applyChartThemeColors(tmpChart, {}, tmpColors)).to.equal(false);
475
+ Expect(tmpChart.updates).to.equal(1);
476
+ });
477
+
478
+ test('a theme change reaches a drawn chart on its next marshal, even when its data has not changed', () =>
479
+ {
480
+ const tmpPict = new libPict();
481
+ const tmpProvider = new libChartInput(tmpPict, {});
482
+ tmpPict.providers.DynamicSolver = { runSolver: () => [ 1, 2, 3 ] };
483
+ const tmpInput =
484
+ {
485
+ Name: 'Themed', Hash: 'Themed', DataType: 'Object',
486
+ Macro: { RawHTMLID: 'Themed-input', InputFullProperties: '', InputChangeHandler: '', ControlAttr: '' },
487
+ PictForm: { InputType: 'Chart', ChartType: 'line', ChartDatasetsSolvers: [ { Label: 'Sold', DataSolver: 'x' } ] },
488
+ };
489
+ addCanvas('Themed-input');
490
+ const tmpChart = fakeChart();
491
+ tmpProvider.currentChartObjects['Object-For-Themed-input'] = tmpChart;
492
+ tmpProvider.currentChartDataObjects['Data-For-Themed-input'] = JSON.stringify(tmpProvider.getInputChartConfiguration({ }, tmpInput, {}).data);
493
+
494
+ let fRestore = stubComputedStyle({ color: 'rgb(20, 20, 20)' });
495
+ try
496
+ {
497
+ tmpProvider.onDataMarshalToForm({ }, { }, { }, tmpInput, null, '', 'T1');
498
+ Expect(tmpChart.options.scales.x.ticks.color).to.equal('rgb(20, 20, 20)');
499
+ }
500
+ finally
501
+ {
502
+ fRestore();
503
+ }
504
+
505
+ fRestore = stubComputedStyle({ color: 'rgb(240, 240, 240)' });
506
+ try
507
+ {
508
+ tmpProvider.onDataMarshalToForm({ }, { }, { }, tmpInput, null, '', 'T2');
509
+ Expect(tmpChart.options.scales.x.ticks.color).to.equal('rgb(240, 240, 240)');
510
+ Expect(tmpChart.options.scales.x.grid.color).to.equal('rgba(240, 240, 240, 0.15)');
511
+ const tmpUpdates = tmpChart.updates;
512
+ tmpProvider.onDataMarshalToForm({ }, { }, { }, tmpInput, null, '', 'T3');
513
+ Expect(tmpChart.updates, 'no redraw when nothing changed').to.equal(tmpUpdates);
514
+ Expect(tmpChart.data, 'data left alone').to.equal(undefined);
515
+ }
516
+ finally
517
+ {
518
+ fRestore();
519
+ }
520
+ });
521
+ });
522
+
194
523
  suite('grouped legend', () =>
195
524
  {
196
525
  const provider = () => new libChartInput(new libPict(), {});