Skip to content

Commit

Permalink
refactor: Moving reversedDirection inside domain namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Dec 23, 2022
1 parent 73fd511 commit 70c67a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/domain/DomainCoordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 9 additions & 7 deletions src/options/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type DomainOptions = {
padding: [number, number, number, number];
dynamicDimension: boolean;
label: LabelOptions;
sort: 'asc' | 'desc';
};

type LabelOptions = {
Expand All @@ -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 = {
Expand All @@ -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);
};

Expand Down Expand Up @@ -84,7 +87,6 @@ export type OptionsType = {
animationDuration: number;
tooltip: boolean | TooltipOptions;
verticalOrientation: boolean;
reversedDirection: boolean;
};

type InternalOptionsType = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/frontend/reversedDirection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down

0 comments on commit 70c67a1

Please sign in to comment.