From 54c5b7a084576d9ccf8f7b6af943b04415e0c321 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Fri, 26 Mar 2021 16:20:59 -0400 Subject: [PATCH] Add a convenience alias for scale options (#8732) * Add a convenience alias for scale options Closes #8731 * Add an automated test * Use parameter for a more realistic test --- types/index.esm.d.ts | 3 +++ types/tests/scales/options.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 421c4ac8b..fea930603 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -3248,6 +3248,9 @@ export type ScaleOptionsByType = { [key in ScaleType]: { type: key } & ScaleTypeRegistry[key]['options'] }[TScale] ; +// Convenience alias for creating and manipulating scale options in user code +export type ScaleOptions = DeepPartial>; + export type DatasetChartOptions = { [key in TType]: { datasets: ChartTypeRegistry[key]['datasetOptions']; diff --git a/types/tests/scales/options.ts b/types/tests/scales/options.ts index cf4f4dcb8..968d89031 100644 --- a/types/tests/scales/options.ts +++ b/types/tests/scales/options.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart, ScaleOptions } from '../../index.esm'; const chart = new Chart('test', { type: 'bar', @@ -30,3 +30,29 @@ const chart = new Chart('test', { } } }); + +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) + } + } +});