pict-section-form 1.3.11 → 1.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "Pict dynamic forms",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -204,9 +204,20 @@ class CustomInputHandler extends libPictSectionInputExtension
204
204
  const tmpState = this.currentChartLegendState[pRawHTMLID] = this.currentChartLegendState[pRawHTMLID] || { Hidden: false, Collapsed: {} };
205
205
  const tmpPosition = pLegendConfiguration.Position || 'right';
206
206
 
207
- // Wrap the canvas once: shell > (canvas area | legend).
208
- let tmpShell = tmpContainer.parentElement && tmpContainer.parentElement.classList.contains('pict-chart-shell')
209
- ? tmpContainer.parentElement : null;
207
+ // Wrap the canvas ONCE: shell > (canvas area | legend).
208
+ //
209
+ // After the first wrap the container's parent is the canvas AREA, not the
210
+ // shell, so testing the immediate parent for 'pict-chart-shell' never matches
211
+ // again and every re-render nests another shell inside the last -- 14 shells
212
+ // and 14 legends for 3 charts after a handful of toggles. Detect the wrapped
213
+ // shape by its own marker and climb to the shell.
214
+ let tmpShell = null;
215
+ const tmpExistingArea = tmpContainer.parentElement;
216
+ if (tmpExistingArea && tmpExistingArea.classList.contains('pict-chart-canvas-area')
217
+ && tmpExistingArea.parentElement && tmpExistingArea.parentElement.classList.contains('pict-chart-shell'))
218
+ {
219
+ tmpShell = tmpExistingArea.parentElement;
220
+ }
210
221
  if (!tmpShell)
211
222
  {
212
223
  tmpShell = document.createElement('div');
@@ -273,6 +273,53 @@ suite('Pict-Provider-Input-Chart', () =>
273
273
  });
274
274
  });
275
275
 
276
+ suite('legend re-entrancy', () =>
277
+ {
278
+ // renderChartLegend runs again on every data refresh and on every toggle.
279
+ // It must reuse the wrapper it already built. It did not: after the first
280
+ // wrap the container's parent is the canvas AREA rather than the shell, so
281
+ // the guard never matched and each call nested another shell — 14 shells and
282
+ // 14 legends for 3 charts in the browser.
283
+ const buildChart = () =>
284
+ {
285
+ const tmpCanvas = document.createElement('canvas');
286
+ const tmpContainer = document.createElement('div');
287
+ tmpContainer.appendChild(tmpCanvas);
288
+ document.body.appendChild(tmpContainer);
289
+ return {
290
+ canvas: tmpCanvas,
291
+ data: { datasets: [ { label: 'Reading' }, { label: 'Limit', pictLegendGroup: 'Limits' } ] },
292
+ getDatasetMeta: () => ({ hidden: false }),
293
+ update: () => {},
294
+ };
295
+ };
296
+
297
+ test('re-rendering reuses the shell instead of nesting another', () =>
298
+ {
299
+ const tmpProvider = new libChartInput(new libPict(), {});
300
+ const tmpChart = buildChart();
301
+ for (let i = 0; i < 5; i++)
302
+ {
303
+ tmpProvider.renderChartLegend('ReentrantChart', tmpChart, { Position: 'right' });
304
+ }
305
+ Expect(document.querySelectorAll('.pict-chart-shell').length, 'shells').to.equal(1);
306
+ Expect(document.querySelectorAll('.pict-chart-legend').length, 'legend panels').to.equal(1);
307
+ Expect(document.querySelectorAll('.pict-chart-shell .pict-chart-shell').length, 'nested shells').to.equal(0);
308
+ // Two datasets in two groups → two items, not ten.
309
+ Expect(document.querySelectorAll('.pict-chart-legend-item').length, 'items').to.equal(2);
310
+ Expect(tmpChart.canvas.closest('.pict-chart-canvas-area'), 'canvas still inside the area').to.be.ok;
311
+ });
312
+
313
+ test('the canvas is never detached from the document by a re-render', () =>
314
+ {
315
+ const tmpProvider = new libChartInput(new libPict(), {});
316
+ const tmpChart = buildChart();
317
+ tmpProvider.renderChartLegend('AttachedChart', tmpChart, { Position: 'right' });
318
+ tmpProvider.renderChartLegend('AttachedChart', tmpChart, { Position: 'right' });
319
+ Expect(document.body.contains(tmpChart.canvas)).to.equal(true);
320
+ });
321
+ });
322
+
276
323
  suite('template', () =>
277
324
  {
278
325
  test('the chart canvas container carries the ChartHeight min-height', () =>