* Add a convenience alias for scale options
Closes #8731
* Add an automated test
* Use parameter for a more realistic test
{ [key in ScaleType]: { type: key } & ScaleTypeRegistry[key]['options'] }[TScale]
;
+// Convenience alias for creating and manipulating scale options in user code
+export type ScaleOptions<TScale extends ScaleType = ScaleType> = DeepPartial<ScaleOptionsByType<TScale>>;
+
export type DatasetChartOptions<TType extends ChartType = ChartType> = {
[key in TType]: {
datasets: ChartTypeRegistry[key]['datasetOptions'];
-import { Chart } from '../../index.esm';
+import { Chart, ScaleOptions } from '../../index.esm';
const chart = new Chart('test', {
type: 'bar',
}
}
});
+
+function makeChartScale(range: number): ScaleOptions<'linear'> {
+ return {
+ type: 'linear',
+ min: 0,
+ suggestedMax: range,
+ };
+}
+
+const composedChart = new Chart('test2', {
+ type: 'bar',
+ data: {
+ labels: ['a'],
+ datasets: [{
+ data: [1],
+ }, {
+ type: 'line',
+ data: [{ x: 1, y: 1 }]
+ }]
+ },
+ options: {
+ scales: {
+ x: makeChartScale(10)
+ }
+ }
+});