pict-section-form 1.3.9 → 1.3.10
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
|
@@ -514,6 +514,17 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
514
514
|
tmpDataObject.stack = tmpCurrentSolverExpression.StackGroup;
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
// DatasetOptions is the general escape hatch: every key is merged onto
|
|
518
|
+
// the Chart.js dataset as-is. Without it a dataset could only carry the
|
|
519
|
+
// handful of properties named above, so a series could not be given a
|
|
520
|
+
// colour, a dash pattern, or told not to join its points -- the config
|
|
521
|
+
// was silently dropped and the chart drew in default colours. It is
|
|
522
|
+
// applied last, so it wins over the named options above.
|
|
523
|
+
if (tmpCurrentSolverExpression.DatasetOptions && (typeof(tmpCurrentSolverExpression.DatasetOptions) === 'object'))
|
|
524
|
+
{
|
|
525
|
+
Object.assign(tmpDataObject, tmpCurrentSolverExpression.DatasetOptions);
|
|
526
|
+
}
|
|
527
|
+
|
|
517
528
|
if (tmpParsingConfiguration.ObjectType === 'array')
|
|
518
529
|
{
|
|
519
530
|
if (Array.isArray(tmpSolvedDataSet))
|
|
@@ -131,6 +131,66 @@ suite('Pict-Provider-Input-Chart', () =>
|
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
+
suite('DatasetOptions', () =>
|
|
135
|
+
{
|
|
136
|
+
// The provider copies a fixed allowlist of properties onto each dataset
|
|
137
|
+
// (ChartType / CustomYAxisID / CustomXAxisID / Tension / PointRadius /
|
|
138
|
+
// StackGroup). Anything else was dropped, so a series could not be given a
|
|
139
|
+
// colour or a dash pattern from configuration at all.
|
|
140
|
+
const solverDataset = (pEntry) =>
|
|
141
|
+
{
|
|
142
|
+
const tmpPict = new libPict();
|
|
143
|
+
const tmpProvider = new libChartInput(tmpPict, {});
|
|
144
|
+
tmpPict.providers.DynamicSolver = { runSolver: () => [ 1, 2, 3 ] };
|
|
145
|
+
const tmpInput =
|
|
146
|
+
{
|
|
147
|
+
Name: 'C', Hash: 'C', DataType: 'Object',
|
|
148
|
+
Macro: { RawHTMLID: 'C-input', InputFullProperties: '', InputChangeHandler: '', ControlAttr: '' },
|
|
149
|
+
PictForm: { InputType: 'Chart', ChartType: 'line', ChartDatasetsSolvers: [ pEntry ] },
|
|
150
|
+
};
|
|
151
|
+
const tmpConfiguration = tmpProvider.getInputChartConfiguration({ }, tmpInput, {});
|
|
152
|
+
return tmpConfiguration.data.datasets[0];
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
test('arbitrary Chart.js dataset properties reach the dataset', () =>
|
|
156
|
+
{
|
|
157
|
+
const tmpDataset = solverDataset({ Label: 'Limit', DataSolver: 'x',
|
|
158
|
+
DatasetOptions: { borderColor: '#E03131', borderDash: [ 2, 3 ], showLine: false } });
|
|
159
|
+
Expect(tmpDataset.borderColor).to.equal('#E03131');
|
|
160
|
+
Expect(tmpDataset.borderDash).to.deep.equal([ 2, 3 ]);
|
|
161
|
+
Expect(tmpDataset.showLine).to.equal(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('label and data still come from Label / DataSolver', () =>
|
|
165
|
+
{
|
|
166
|
+
const tmpDataset = solverDataset({ Label: 'Limit', DataSolver: 'x', DatasetOptions: { borderColor: '#000' } });
|
|
167
|
+
Expect(tmpDataset.label).to.equal('Limit');
|
|
168
|
+
Expect(tmpDataset.data).to.deep.equal([ 1, 2, 3 ]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('it wins over the named options, being applied last', () =>
|
|
172
|
+
{
|
|
173
|
+
const tmpDataset = solverDataset({ Label: 'L', DataSolver: 'x', PointRadius: 9, DatasetOptions: { pointRadius: 2 } });
|
|
174
|
+
Expect(tmpDataset.pointRadius).to.equal(2);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('a dataset without DatasetOptions is unchanged', () =>
|
|
178
|
+
{
|
|
179
|
+
const tmpDataset = solverDataset({ Label: 'L', DataSolver: 'x' });
|
|
180
|
+
Expect(tmpDataset).to.not.have.property('borderColor');
|
|
181
|
+
Expect(Object.keys(tmpDataset)).to.deep.equal([ 'label', 'data' ]);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('a non-object DatasetOptions is ignored rather than throwing', () =>
|
|
185
|
+
{
|
|
186
|
+
for (const tmpBad of [ 'nope', 42, null ])
|
|
187
|
+
{
|
|
188
|
+
const tmpDataset = solverDataset({ Label: 'L', DataSolver: 'x', DatasetOptions: tmpBad });
|
|
189
|
+
Expect(tmpDataset.label, `DatasetOptions ${JSON.stringify(tmpBad)}`).to.equal('L');
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
134
194
|
suite('template', () =>
|
|
135
195
|
{
|
|
136
196
|
test('the chart canvas container carries the ChartHeight min-height', () =>
|