pict-section-form 1.3.17 → 1.4.1

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.3.17",
3
+ "version": "1.4.1",
4
4
  "description": "Pict dynamic forms",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -260,7 +260,7 @@ Glug glug glug Oo... -->
260
260
  "DefaultInputExtensions": ["Pict-Input-Chart"],
261
261
  "Template": /*HTML*/`
262
262
  <!-- InputType Chart {~D:Record.Hash~} {~D:Record.DataType~} -->
263
- <div style="width:{~DWAF:Record.PictForm.QuantizedWidth:100~}%; display:inline-block;">
263
+ <div style="width:{~DWAF:Record.PictForm.QuantizedWidth:100~}%; margin-left:{~DWAF:Record.PictForm.QuantizedWidthOffset:0~}%; display:inline-block;">
264
264
  <input type="hidden" id="CONFIG-FOR-{~D:Record.Macro.RawHTMLID~}" value="">
265
265
  <h3><span>{~D:Record.Name~}:</span></h3>
266
266
  <!-- ChartHeight (pixels) sets the plot area. It is min-height rather than height so the
@@ -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
  }
@@ -12,6 +12,40 @@ class RecordLayout extends libPictSectionGroupLayout
12
12
  this.fable;
13
13
  /** @type {any} */
14
14
  this.log;
15
+
16
+ /** @type {Array<(pInput: any) => boolean>} */
17
+ this.layoutExcludedInputChecks = [];
18
+ }
19
+
20
+ /**
21
+ * Register a check that marks an input as taking no width in its row. An excluded
22
+ * input gets `PictForm.LayoutExcluded = true` and a QuantizedWidth of 0, and the
23
+ * other inputs in the row share its space.
24
+ *
25
+ * @param {(pInput: any) => boolean} fCheck - returns true when the input takes no width
26
+ */
27
+ registerLayoutExcludedInputCheck(fCheck)
28
+ {
29
+ if ((typeof fCheck === 'function') && !this.layoutExcludedInputChecks.includes(fCheck))
30
+ {
31
+ this.layoutExcludedInputChecks.push(fCheck);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @param {any} pInput
37
+ * @returns {boolean} - true when any registered check excludes the input from row width
38
+ */
39
+ isLayoutExcludedInput(pInput)
40
+ {
41
+ for (let i = 0; i < this.layoutExcludedInputChecks.length; i++)
42
+ {
43
+ if (this.layoutExcludedInputChecks[i](pInput))
44
+ {
45
+ return true;
46
+ }
47
+ }
48
+ return false;
15
49
  }
16
50
 
17
51
  /**
@@ -76,8 +110,20 @@ class RecordLayout extends libPictSectionGroupLayout
76
110
  {
77
111
  tmpInputWidth = 1;
78
112
  }
113
+ let tmpInputWidthOffset = Math.abs(parseFloat(tmpInput.PictForm.WidthOffset));
114
+ if (!tmpInputWidthOffset || isNaN(tmpInputWidthOffset))
115
+ {
116
+ tmpInputWidthOffset = 0;
117
+ }
118
+ tmpInput.PictForm.LayoutExcluded = this.isLayoutExcludedInput(tmpInput);
119
+ if (tmpInput.PictForm.LayoutExcluded)
120
+ {
121
+ tmpInputWidth = 0;
122
+ tmpInputWidthOffset = 0;
123
+ }
79
124
  tmpInput.PictForm.RawWidth = tmpInputWidth;
80
- tmpRow.WidthTotalRaw += tmpInputWidth;
125
+ tmpInput.PictForm.RawWidthOffset = tmpInputWidthOffset;
126
+ tmpRow.WidthTotalRaw += tmpInputWidth + tmpInputWidthOffset;
81
127
 
82
128
  //tmpTemplate += tmpMetatemplateGenerator.getInputMetatemplateTemplateReference(pView, tmpInput.DataType, tmpInput.PictForm.InputType, `getInput("${pGroup.GroupIndex}","${j}","${k}")`);
83
129
  }
@@ -107,7 +153,16 @@ class RecordLayout extends libPictSectionGroupLayout
107
153
  for (let k = 0; k < tmpRow.Inputs.length; k++)
108
154
  {
109
155
  let tmpInput = tmpRow.Inputs[k];
110
- tmpInput.PictForm.QuantizedWidth = Math.round((tmpInput.PictForm.RawWidth / tmpRow.WidthTotalRaw) * tmpGroupQuantizedWidth);
156
+ if (tmpRow.WidthTotalRaw > 0)
157
+ {
158
+ tmpInput.PictForm.QuantizedWidth = Math.round((tmpInput.PictForm.RawWidth / tmpRow.WidthTotalRaw) * tmpGroupQuantizedWidth);
159
+ tmpInput.PictForm.QuantizedWidthOffset = Math.round((tmpInput.PictForm.RawWidthOffset / tmpRow.WidthTotalRaw) * tmpGroupQuantizedWidth);
160
+ }
161
+ else
162
+ {
163
+ tmpInput.PictForm.QuantizedWidth = 0;
164
+ tmpInput.PictForm.QuantizedWidthOffset = 0;
165
+ }
111
166
  //this.fable.log.trace(`Quantized input width for Group ${pGroup.GroupIndex} Row ${j} Input ${k} (${tmpInput.Name}) to ${tmpInput.PictForm.QuantizedWidth} (Raw: ${tmpInput.PictForm.RawWidth} / Total Raw: ${tmpRow.WidthTotalRaw} / Group Quantization: ${tmpGroupQuantizedWidth})`);
112
167
 
113
168
  tmpTemplate += tmpMetatemplateGenerator.getInputMetatemplateTemplateReference(pView, tmpInput.DataType, tmpInput.PictForm.InputType, `getInput("${pGroup.GroupIndex}","${j}","${k}")`);
@@ -1577,6 +1577,68 @@ class TabularLayout extends libPictSectionGroupLayout
1577
1577
  return true;
1578
1578
  }
1579
1579
 
1580
+ /**
1581
+ * A `<colgroup>` sizing the visible data columns as percentages of the table,
1582
+ * in proportion to each descriptor's `PictForm.Width` (missing, zero or
1583
+ * unparseable counts as 1, as in the Record layout). Leading non-data columns
1584
+ * get an unsized `<col>` so the data widths line up.
1585
+ *
1586
+ * Returns an empty string when no visible column carries a positive Width, so
1587
+ * tables without widths keep the browser's automatic column sizing.
1588
+ *
1589
+ * @param {Object} pGroup
1590
+ * @param {Set<string>|null} pChooserHiddenSet - columns hidden by the ColumnChooser
1591
+ * @param {number} pLeadingColumnCount - row-select, row label and left editing-control columns
1592
+ * @returns {string}
1593
+ */
1594
+ _buildTabularColGroupHTML(pGroup, pChooserHiddenSet, pLeadingColumnCount)
1595
+ {
1596
+ let tmpRawWidths = [];
1597
+ let tmpAnyWidth = false;
1598
+ for (let k = 0; k < pGroup.supportingManifest.elementAddresses.length; k++)
1599
+ {
1600
+ let tmpHash = pGroup.supportingManifest.elementAddresses[k];
1601
+ let tmpDescriptor = pGroup.supportingManifest.elementDescriptors[tmpHash];
1602
+ if (!tmpDescriptor || (tmpDescriptor.PictForm && tmpDescriptor.PictForm.TabularHidden))
1603
+ {
1604
+ continue;
1605
+ }
1606
+ if (pChooserHiddenSet && pChooserHiddenSet.has(String(tmpHash)))
1607
+ {
1608
+ continue;
1609
+ }
1610
+ let tmpWidth = Math.abs(parseFloat(tmpDescriptor.PictForm ? tmpDescriptor.PictForm.Width : undefined));
1611
+ if (!tmpWidth || isNaN(tmpWidth))
1612
+ {
1613
+ tmpWidth = 1;
1614
+ }
1615
+ else
1616
+ {
1617
+ tmpAnyWidth = true;
1618
+ }
1619
+ tmpRawWidths.push(tmpWidth);
1620
+ }
1621
+
1622
+ if (!tmpAnyWidth)
1623
+ {
1624
+ return '';
1625
+ }
1626
+
1627
+ let tmpTotal = tmpRawWidths.reduce((pSum, pWidth) => pSum + pWidth, 0);
1628
+ let tmpColGroup = '<colgroup class="pict-tabular-colgroup">';
1629
+ for (let l = 0; l < pLeadingColumnCount; l++)
1630
+ {
1631
+ tmpColGroup += '<col>';
1632
+ }
1633
+ for (let c = 0; c < tmpRawWidths.length; c++)
1634
+ {
1635
+ let tmpPercent = Math.round((tmpRawWidths[c] / tmpTotal) * 10000) / 100;
1636
+ tmpColGroup += `<col style="width:${tmpPercent}%">`;
1637
+ }
1638
+ tmpColGroup += '</colgroup>';
1639
+ return tmpColGroup;
1640
+ }
1641
+
1580
1642
  /**
1581
1643
  * Generate a group layout template for a single-record dynamically generated group view.
1582
1644
  *
@@ -1663,6 +1725,9 @@ class TabularLayout extends libPictSectionGroupLayout
1663
1725
 
1664
1726
  tmpTemplate += tmpMetatemplateGenerator.getMetatemplateTemplateReference(pView, `-TabularTemplate-Group-Prefix`, `getGroup("${pGroup.GroupIndex}")`);
1665
1727
 
1728
+ // Group-Prefix ends with the <table> open tag and RowHeader-Prefix starts with <thead>.
1729
+ tmpTemplate += this._buildTabularColGroupHTML(pGroup, tmpChooserHiddenSet, tmpLeadingColumnCount);
1730
+
1666
1731
  // Header section
1667
1732
  tmpTemplate += tmpMetatemplateGenerator.getMetatemplateTemplateReference(pView, `-TabularTemplate-RowHeader-Prefix`, `getGroup("${pGroup.GroupIndex}")`);
1668
1733
 
@@ -0,0 +1,110 @@
1
+ /*
2
+ Unit tests for the Record layout's row width math: PictForm.Width / WidthOffset quantized to
3
+ QuantizedWidth / QuantizedWidthOffset, and inputs excluded from row width by a registered check.
4
+ Exercised against a stub `this` so we don't need to mount a full form.
5
+ */
6
+
7
+ const Chai = require('chai');
8
+ const Expect = Chai.expect;
9
+
10
+ const libRecordLayout = require('../source/providers/layouts/Pict-Layout-Record.js');
11
+
12
+ function buildLayout()
13
+ {
14
+ const tmpLayout = Object.create(libRecordLayout.prototype);
15
+ tmpLayout.layoutExcludedInputChecks = [];
16
+ tmpLayout.pict =
17
+ {
18
+ PictApplication: { options: {} },
19
+ providers:
20
+ {
21
+ MetatemplateGenerator:
22
+ {
23
+ getMetatemplateTemplateReference: () => '',
24
+ getInputMetatemplateTemplateReference: () => ''
25
+ }
26
+ }
27
+ };
28
+ return tmpLayout;
29
+ }
30
+
31
+ function buildGroup(pInputs, pWidthQuantization)
32
+ {
33
+ const tmpGroup = { GroupIndex: 0, Rows: [ { Hash: 'Row_1', RowNumber: 1, Inputs: pInputs } ] };
34
+ if (pWidthQuantization)
35
+ {
36
+ tmpGroup.WidthQuantization = pWidthQuantization;
37
+ }
38
+ return tmpGroup;
39
+ }
40
+
41
+ function input(pHash, pPictForm)
42
+ {
43
+ return { Hash: pHash, DataType: 'String', PictForm: Object.assign({}, pPictForm) };
44
+ }
45
+
46
+ function widths(pGroup)
47
+ {
48
+ return pGroup.Rows[0].Inputs.map((pInput) => [ pInput.PictForm.QuantizedWidth, pInput.PictForm.QuantizedWidthOffset ]);
49
+ }
50
+
51
+ suite('Record layout row widths', () =>
52
+ {
53
+ test('widths without offsets quantize as before (default 95)', () =>
54
+ {
55
+ const tmpGroup = buildGroup([ input('A', { Width: 1 }), input('B', { Width: 3 }) ]);
56
+ buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
57
+ Expect(widths(tmpGroup)).to.deep.equal([ [ 24, 0 ], [ 71, 0 ] ]);
58
+ });
59
+
60
+ test('offsets count toward the row total and quantize to QuantizedWidthOffset', () =>
61
+ {
62
+ const tmpGroup = buildGroup([ input('A', { Width: 2, WidthOffset: 1 }), input('B', { Width: 3 }) ], 100);
63
+ buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
64
+ Expect(widths(tmpGroup)).to.deep.equal([ [ 33, 17 ], [ 50, 0 ] ]);
65
+ });
66
+
67
+ test('a row authored to 12 with offsets keeps its proportions', () =>
68
+ {
69
+ const tmpGroup = buildGroup([ input('A', { Width: 3, WidthOffset: 3 }), input('B', { Width: '6' }) ], 100);
70
+ buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
71
+ Expect(widths(tmpGroup)).to.deep.equal([ [ 25, 25 ], [ 50, 0 ] ]);
72
+ });
73
+
74
+ test('zero, missing and unparseable widths count as 1; bad offsets count as 0', () =>
75
+ {
76
+ const tmpGroup = buildGroup([ input('A', { Width: 0 }), input('B', {}), input('C', { Width: 'wide', WidthOffset: 'x' }), input('D', { Width: 1 }) ], 100);
77
+ buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
78
+ Expect(widths(tmpGroup)).to.deep.equal([ [ 25, 0 ], [ 25, 0 ], [ 25, 0 ], [ 25, 0 ] ]);
79
+ });
80
+
81
+ test('an input excluded by a registered check takes no width and the rest share the row', () =>
82
+ {
83
+ const tmpLayout = buildLayout();
84
+ tmpLayout.registerLayoutExcludedInputCheck((pInput) => pInput.PictForm.InputType === 'Invisible');
85
+ const tmpGroup = buildGroup([ input('A', { Width: 6, WidthOffset: 2, InputType: 'Invisible' }), input('B', { Width: 1 }), input('C', { Width: 1 }) ], 100);
86
+ tmpLayout.generateGroupLayoutTemplate({}, tmpGroup);
87
+ Expect(widths(tmpGroup)).to.deep.equal([ [ 0, 0 ], [ 50, 0 ], [ 50, 0 ] ]);
88
+ Expect(tmpGroup.Rows[0].Inputs.map((pInput) => pInput.PictForm.LayoutExcluded)).to.deep.equal([ true, false, false ]);
89
+ });
90
+
91
+ test('a row where every input is excluded gets zero widths, not NaN', () =>
92
+ {
93
+ const tmpLayout = buildLayout();
94
+ tmpLayout.registerLayoutExcludedInputCheck(() => true);
95
+ const tmpGroup = buildGroup([ input('A', { Width: 2 }), input('B', {}) ], 100);
96
+ tmpLayout.generateGroupLayoutTemplate({}, tmpGroup);
97
+ Expect(widths(tmpGroup)).to.deep.equal([ [ 0, 0 ], [ 0, 0 ] ]);
98
+ });
99
+
100
+ test('registering ignores non-functions and the same check twice', () =>
101
+ {
102
+ const tmpLayout = buildLayout();
103
+ const fCheck = () => false;
104
+ tmpLayout.registerLayoutExcludedInputCheck(fCheck);
105
+ tmpLayout.registerLayoutExcludedInputCheck(fCheck);
106
+ tmpLayout.registerLayoutExcludedInputCheck('not a function');
107
+ Expect(tmpLayout.layoutExcludedInputChecks).to.have.length(1);
108
+ Expect(tmpLayout.isLayoutExcludedInput(input('A', {}))).to.equal(false);
109
+ });
110
+ });
@@ -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(), {});
@@ -39,6 +39,27 @@ const _ReferenceManifests =
39
39
  }
40
40
  }
41
41
  },
42
+ SizedStudentEditor:
43
+ {
44
+ Scope: 'SizedStudentEditor',
45
+ Descriptors:
46
+ {
47
+ Section:
48
+ {
49
+ Name: 'Section',
50
+ Hash: 'Section',
51
+ DataType: 'String',
52
+ PictForm: { Section: 'Class', Group: 'Students', Width: 1 }
53
+ },
54
+ StudentName:
55
+ {
56
+ Name: 'Student',
57
+ Hash: 'StudentName',
58
+ DataType: 'String',
59
+ PictForm: { Section: 'Class', Group: 'Students', Width: 3 }
60
+ }
61
+ }
62
+ },
42
63
  GradeRowEditor:
43
64
  {
44
65
  Scope: 'GradeRowEditor',
@@ -2034,4 +2055,118 @@ suite('PictSectionForm Tabular Features', () =>
2034
2055
  }, fDone);
2035
2056
  });
2036
2057
  });
2058
+
2059
+ suite('Tabular column widths (PictForm.Width)', () =>
2060
+ {
2061
+ function makeGroup(pDescriptors)
2062
+ {
2063
+ return { supportingManifest: { elementAddresses: Object.keys(pDescriptors), elementDescriptors: pDescriptors } };
2064
+ }
2065
+
2066
+ test('No colgroup when no column carries a Width', (fDone) =>
2067
+ {
2068
+ let App = makeApplication({
2069
+ Hash: 'Students',
2070
+ Layout: 'Tabular',
2071
+ RecordSetAddress: 'Students',
2072
+ RecordManifest: 'StudentEditor'
2073
+ });
2074
+ bootstrap(App, (_Pict) =>
2075
+ {
2076
+ let tmpView = _Pict.views['PictSectionForm-Class'];
2077
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
2078
+ let tmpTemplate = _Pict.providers['Pict-Layout-Tabular'].generateGroupLayoutTemplate(tmpView, tmpGroup);
2079
+ Expect(tmpTemplate).to.not.contain('<colgroup', 'tables without widths keep automatic sizing');
2080
+ }, fDone);
2081
+ });
2082
+
2083
+ test('Widths become percentages in a colgroup between the table open and the header', (fDone) =>
2084
+ {
2085
+ let App = makeApplication({
2086
+ Hash: 'Students',
2087
+ Layout: 'Tabular',
2088
+ RecordSetAddress: 'Students',
2089
+ RecordManifest: 'SizedStudentEditor'
2090
+ });
2091
+ bootstrap(App, (_Pict) =>
2092
+ {
2093
+ let tmpView = _Pict.views['PictSectionForm-Class'];
2094
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
2095
+ let tmpTemplate = _Pict.providers['Pict-Layout-Tabular'].generateGroupLayoutTemplate(tmpView, tmpGroup);
2096
+ Expect(tmpTemplate).to.contain('<colgroup class="pict-tabular-colgroup"><col style="width:25%"><col style="width:75%"></colgroup>');
2097
+ let tmpColGroupAt = tmpTemplate.indexOf('<colgroup');
2098
+ Expect(tmpColGroupAt).to.be.greaterThan(tmpTemplate.indexOf('-TabularTemplate-Group-Prefix'), 'after the table open');
2099
+ Expect(tmpColGroupAt).to.be.lessThan(tmpTemplate.indexOf('-TabularTemplate-RowHeader-Prefix'), 'before the header');
2100
+ }, fDone);
2101
+ });
2102
+
2103
+ test('Columns without a usable Width count as 1; zero is not hidden', (fDone) =>
2104
+ {
2105
+ let App = makeApplication({
2106
+ Hash: 'Students',
2107
+ Layout: 'Tabular',
2108
+ RecordSetAddress: 'Students',
2109
+ RecordManifest: 'StudentEditor'
2110
+ });
2111
+ bootstrap(App, (_Pict) =>
2112
+ {
2113
+ let tmpLayout = _Pict.providers['Pict-Layout-Tabular'];
2114
+ let tmpHTML = tmpLayout._buildTabularColGroupHTML(makeGroup(
2115
+ {
2116
+ A: { Hash: 'A', PictForm: { Width: 2 } },
2117
+ B: { Hash: 'B', PictForm: { Width: 0 } },
2118
+ C: { Hash: 'C', PictForm: { Width: 'wide' } },
2119
+ D: { Hash: 'D' }
2120
+ }), null, 0);
2121
+ Expect(tmpHTML).to.equal('<colgroup class="pict-tabular-colgroup"><col style="width:40%"><col style="width:20%"><col style="width:20%"><col style="width:20%"></colgroup>');
2122
+ let tmpZeroHTML = tmpLayout._buildTabularColGroupHTML(makeGroup(
2123
+ {
2124
+ A: { Hash: 'A', PictForm: { Width: 0 } },
2125
+ B: { Hash: 'B', PictForm: { Width: 0 } }
2126
+ }), null, 0);
2127
+ Expect(tmpZeroHTML).to.equal('', 'all-zero widths size nothing');
2128
+ }, fDone);
2129
+ });
2130
+
2131
+ test('Hidden columns are skipped and leading columns get unsized cols', (fDone) =>
2132
+ {
2133
+ let App = makeApplication({
2134
+ Hash: 'Students',
2135
+ Layout: 'Tabular',
2136
+ RecordSetAddress: 'Students',
2137
+ RecordManifest: 'StudentEditor'
2138
+ });
2139
+ bootstrap(App, (_Pict) =>
2140
+ {
2141
+ let tmpLayout = _Pict.providers['Pict-Layout-Tabular'];
2142
+ let tmpHTML = tmpLayout._buildTabularColGroupHTML(makeGroup(
2143
+ {
2144
+ A: { Hash: 'A', PictForm: { Width: 1 } },
2145
+ Secret: { Hash: 'Secret', PictForm: { Width: 50, TabularHidden: true } },
2146
+ Chosen: { Hash: 'Chosen', PictForm: { Width: 50 } },
2147
+ B: { Hash: 'B', PictForm: { Width: 2 } }
2148
+ }), new Set([ 'Chosen' ]), 2);
2149
+ Expect(tmpHTML).to.equal('<colgroup class="pict-tabular-colgroup"><col><col><col style="width:33.33%"><col style="width:66.67%"></colgroup>');
2150
+ }, fDone);
2151
+ });
2152
+
2153
+ test('Chooser-hidden columns drop out of the baked colgroup', (fDone) =>
2154
+ {
2155
+ let App = makeApplication({
2156
+ Hash: 'Students',
2157
+ Layout: 'Tabular',
2158
+ RecordSetAddress: 'Students',
2159
+ RecordManifest: 'SizedStudentEditor',
2160
+ ColumnChooser: true,
2161
+ RowSelection: true
2162
+ }, { Students_HiddenColumns: [ 'StudentName' ] });
2163
+ bootstrap(App, (_Pict) =>
2164
+ {
2165
+ let tmpView = _Pict.views['PictSectionForm-Class'];
2166
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
2167
+ let tmpTemplate = _Pict.providers['Pict-Layout-Tabular'].generateGroupLayoutTemplate(tmpView, tmpGroup);
2168
+ Expect(tmpTemplate).to.contain('<colgroup class="pict-tabular-colgroup"><col><col style="width:100%"></colgroup>', 'row-select col, then the one visible column');
2169
+ }, fDone);
2170
+ });
2171
+ });
2037
2172
  });