-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
types.ts
176 lines (153 loc) · 4.11 KB
/
types.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
import * as React from 'react'
import { ScaleDiverging, ScaleQuantize, ScaleSequential } from 'd3-scale'
import { CompleteTheme, ValueFormat } from '@nivo/core'
import { SymbolProps } from './svg/symbols/types'
/**
* This can be used to add effect on legends on interaction.
*/
type EffectProps = {
on: 'hover'
style: Partial<{
itemTextColor: string
itemBackground: string
itemOpacity: number
symbolSize: number
symbolBorderWidth: number
symbolBorderColor: string
}>
}
type SymbolShape = 'circle' | 'diamond' | 'square' | 'triangle'
type BoxLegendSymbolProps = Partial<{
symbolShape: SymbolShape | React.FC<SymbolProps>
symbolSize: number
symbolSpacing: number
symbolBorderWidth: number
symbolBorderColor: string
}>
type InteractivityProps = Partial<
Record<
'onClick' | 'onMouseEnter' | 'onMouseLeave',
(datum: Datum, event: React.MouseEvent<SVGRectElement>) => void
> & {
toggleSerie: (id: Datum['id']) => void
}
>
export type LegendAnchor =
| 'top'
| 'top-right'
| 'right'
| 'bottom-right'
| 'bottom'
| 'bottom-left'
| 'left'
| 'top-left'
| 'center'
export type LegendDirection = 'column' | 'row'
export type LegendItemDirection =
| 'left-to-right'
| 'right-to-left'
| 'top-to-bottom'
| 'bottom-to-top'
export type Datum = {
id: string | number
label: string | number
hidden?: boolean
color?: string
fill?: string
}
type CommonLegendProps = {
data?: Datum[]
direction: LegendDirection
padding?: number | Partial<Record<'top' | 'right' | 'bottom' | 'left', number>>
justify?: boolean
itemWidth: number
itemHeight: number
itemDirection?: LegendItemDirection
itemTextColor?: string
itemBackground?: string
itemOpacity?: number
itemsSpacing?: number
effects?: EffectProps[]
}
export type LegendProps = {
translateX?: number
translateY?: number
anchor: LegendAnchor
toggleSerie?: boolean
} & CommonLegendProps &
BoxLegendSymbolProps &
Omit<InteractivityProps, 'toggleSerie'>
export type BoxLegendSvgProps = {
containerWidth: number
containerHeight: number
} & Omit<LegendProps, 'toggleSerie'> &
Required<Pick<LegendProps, 'data'>> &
Omit<InteractivityProps, 'toggleSerie'> &
Partial<{
toggleSerie: boolean | InteractivityProps['toggleSerie']
}>
export type LegendSvgProps = {
x: number
y: number
} & CommonLegendProps &
Required<Pick<CommonLegendProps, 'data'>> &
BoxLegendSymbolProps &
InteractivityProps
export type LegendSvgItemProps = {
data: Datum
x: number
y: number
width: number
height: number
textColor?: string
background?: string
opacity?: number
direction?: LegendItemDirection
} & Pick<CommonLegendProps, 'justify' | 'effects'> &
BoxLegendSymbolProps &
InteractivityProps
export type LegendCanvasProps = {
containerWidth: number
containerHeight: number
translateX?: number
translateY?: number
anchor: LegendAnchor
symbolSize?: number
symbolSpacing?: number
theme: CompleteTheme
} & Required<Pick<CommonLegendProps, 'data'>> &
Pick<
CommonLegendProps,
| 'direction'
| 'padding'
| 'justify'
| 'itemsSpacing'
| 'itemWidth'
| 'itemHeight'
| 'itemDirection'
| 'itemTextColor'
>
export interface ContinuousColorsLegendProps {
scale: ScaleSequential<string> | ScaleDiverging<string> | ScaleQuantize<string>
ticks?: number | number[]
length?: number
thickness?: number
direction?: LegendDirection
borderWidth?: number
borderColor?: string
tickPosition?: 'before' | 'after'
tickSize?: number
tickSpacing?: number
tickOverlap?: boolean
tickFormat?: ValueFormat<number>
title?: string
titleAlign?: 'start' | 'middle' | 'end'
titleOffset?: number
}
export type AnchoredContinuousColorsLegendProps = ContinuousColorsLegendProps & {
anchor: LegendAnchor
translateX?: number
translateY?: number
containerWidth: number
containerHeight: number
}