-
Notifications
You must be signed in to change notification settings - Fork 180
/
axis-scales.ts
226 lines (217 loc) · 5.13 KB
/
axis-scales.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import type { AxisDomain } from 'd3'
import type { Locale } from 'date-fns/locale'
import type { AxisTitleOrientations, ScaleTypes, TickRotations } from './enums'
import type { ThresholdOptions } from './components'
import type { TruncationOptions } from './truncation'
export interface BasedAxisOptions {
/**
* type of the scale used on axis
*/
scaleType?: ScaleTypes
/**
* Whether the Axis should use the specified domain
* instead of it being dynamically generated based on data extents.
* The type of values should depend on the scale type.
* Example for continuous axis scale: [-100, 100]
* Example for discrete axis scale: ['Qty', 'More', 'Sold']
* No need to define domain for percentage axis scale
*/
domain?: AxisDomain[]
/**
* an additional key from the charting data that is used to
* extend the domain of an axis by
* (e.g. in the bullet graph we need both the marker &
* the data values to define the domain of the linear scale)
*/
extendLinearDomainBy?: string
/**
* Whether the Axis should be forced to include 0 as a starting point
* (or ending point, in case of all negative axis).
* Default: true
*/
includeZero?: boolean
/**
* identifies what key within the data the axis values would map to
*/
mapsTo?: string
/**
* optional title for the scales
*/
title?: string
/**
* Override for the orientation of the title (for vertical axes).
* The title string can be overrided to be rotated left or right.
*/
titleOrientation?: AxisTitleOrientations
/**
* thresholds
* @example
* [
* { value: 10000 },
* { value: 40020, valueFormatter: (x) => x },
* { value: 55000, label: "Custom label", fillColor: "#03a9f4" },
* ]
*/
thresholds?: ThresholdOptions[]
/**
* tick configuration
*/
ticks?: {
/**
* number of ticks to show
*/
number?: number
/**
* minimum tick value
*/
min?: number
/**
* maximum tick value
*/
max?: number
/**
* minimum width of a tick
* before getting rotated (in pixels)
*/
rotateIfSmallerThan?: number
/**
* when to rotate ticks
*/
rotation?: TickRotations
/**
* function to format the ticks
*/
formatter?: (tick: number | Date, i: number) => string
/**
* optional custom array of tick values that is within the domain of data
*/
values?: any[]
}
truncation?: TruncationOptions
/**
* is axis visible or not
*/
visible?: boolean
/**
* Bins to display (Histogram)
* bins: 20
* bins: [0, 20, 40, 60]
* bins: [new Date(...), new Date(...), ...]
*/
bins?: number | any[]
/**
* limit the visible axis domain to only the binned area
*/
limitDomainToBins?: boolean
/**
* should be set to `true` on the domain
* axis that's being broken into bins
*/
binned?: boolean
}
/**
* options to configure a scale. not all options are used by all scales
*/
export interface AxisOptions extends BasedAxisOptions {
/**
* option for stacked axis
*/
stacked?: boolean
/**
* option for percentage axis scale
*/
percentage?: boolean
}
export interface ComboChartAxisOptions extends AxisOptions {
/**
* should be set to `true` for the
* left axis to be the primary axis
*/
main?: boolean
/**
* used to map data on the secondary axis
*/
correspondingDatasets?: Array<string>
}
export interface BinnedAxisOptions {
/**
* should be set to `true` on the domain
* axis that's being broken into bins
*/
binned?: boolean
/**
* Bins to display (Histogram)
* bins: 20
* bins: [0, 20, 40, 60]
* bins: [new Date(...), new Date(...), ...]
*/
bins?: number | any[]
/**
* limit the visible axis domain to only the binned area
*/
limitDomainToBins?: boolean
}
/**
* customize time series scales
*/
export interface TimeScaleOptions {
addSpaceOnEdges?: number
/**
* if it's true, days are shown as mon-sun,
* otherwise days are shown as number 1-31
*/
showDayName?: boolean
/**
* this can be used to override the time interval
* that's chosen by the library
*/
timeInterval?: TimeIntervalNames
/**
* formats for each time interval
*/
timeIntervalFormats?: TimeIntervalFormats
/**
* locale object, for more information see https://date-fns.org/v2.11.0/docs/Locale.
* example: `import { fr as localeObject } from 'date-fns/locale'`.
* available locale objects are: https://github.com/date-fns/date-fns/tree/master/src/locale
*/
localeObject?: Locale
}
/**
* time scales: customize ticks format for different time intervals
*/
export interface TickFormats {
primary?: string
secondary?: string
}
export enum TimeIntervalNames {
'15seconds' = '15seconds',
minute = 'minute',
'30minutes' = '30minutes',
hourly = 'hourly',
daily = 'daily',
weekly = 'weekly',
monthly = 'monthly',
quarterly = 'quarterly',
yearly = 'yearly'
}
export interface TimeIntervalFormats {
'15seconds'?: TickFormats
minute?: TickFormats
'30minutes'?: TickFormats
hourly?: TickFormats
daily?: TickFormats
weekly?: TickFormats
monthly?: TickFormats
quarterly?: TickFormats
yearly?: TickFormats
}
/**
* customize the axes components
*/
export interface AxesOptions<AxesOptionType> {
left?: AxesOptionType
bottom?: AxesOptionType
right?: AxesOptionType
top?: AxesOptionType
}