From 70c67a1d766f02496eb00f5e54817f77321e501a Mon Sep 17 00:00:00 2001 From: wa0x6e Date: Sat, 24 Dec 2022 02:41:41 +0400 Subject: [PATCH] refactor: Moving `reversedDirection` inside `domain` namespace --- src/domain/DomainCoordinates.ts | 2 +- src/options/Options.ts | 16 +++++++++------- test/frontend/reversedDirection.test.ts | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/domain/DomainCoordinates.ts b/src/domain/DomainCoordinates.ts index c3f9a343..7755ec13 100644 --- a/src/domain/DomainCoordinates.ts +++ b/src/domain/DomainCoordinates.ts @@ -46,7 +46,7 @@ export default class DomainCoordinates { let scrollFactor = scrollDirection === ScrollDirection.SCROLL_FORWARD ? -1 : 1; const { keys } = collection; - if (this.calendar.options.options.reversedDirection) { + if (this.calendar.options.options.domain.sort === 'desc') { keys.reverse(); scrollFactor *= -1; } diff --git a/src/options/Options.ts b/src/options/Options.ts index 7ac074bb..4c21683f 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -10,6 +10,7 @@ export type DomainOptions = { padding: [number, number, number, number]; dynamicDimension: boolean; label: LabelOptions; + sort: 'asc' | 'desc'; }; type LabelOptions = { @@ -36,7 +37,9 @@ export type SubDomainOptions = { | null | ((timestamp: number, value: number, element: SVGElement) => string); title: (timestamp: number, value: number) => string; - color?: string | Function; + color?: + | string + | ((timestamp: number, value: number, backgroundColor: string) => string); }; type DateOptions = { @@ -52,8 +55,8 @@ export type DataOptions = { source: any; type: string; requestInit: object; - x: string; - y: string; + x: string | ((datum: any) => number); + y: string | ((data: any[]) => number[]); groupY: string | ((values: number[]) => number); }; @@ -84,7 +87,6 @@ export type OptionsType = { animationDuration: number; tooltip: boolean | TooltipOptions; verticalOrientation: boolean; - reversedDirection: boolean; }; type InternalOptionsType = { @@ -126,6 +128,9 @@ export default class Options { // subDomains items count dynamicDimension: true, + // Whether to show most recent date first + sort: 'asc', + label: { // Formatting of the domain label // @default: undefined, will use the formatting @@ -224,9 +229,6 @@ export default class Options { // true : display domains one under the other verticalOrientation: false, - // Whether to show most recent date first - reversedDirection: false, - data: { // Data source // URL, where to fetch the original datas diff --git a/test/frontend/reversedDirection.test.ts b/test/frontend/reversedDirection.test.ts index a0763fe0..5671f0c4 100644 --- a/test/frontend/reversedDirection.test.ts +++ b/test/frontend/reversedDirection.test.ts @@ -50,7 +50,7 @@ describe('on reversed direction', () => { cal.paint({ range: 12, - reversedDirection: true, + domain: { sort: 'desc' }, date: { start: new Date(2020, 0, 1, 0, 0, 0), },