gifted-charts-core 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -4
- package/src/BarChart/Animated2DWithGradient.ts +80 -46
- package/src/BarChart/RenderStackBars.ts +41 -41
- package/src/BarChart/index.ts +308 -278
- package/src/BarChart/types.ts +574 -572
- package/src/LineChart/LineChartBiColor.ts +272 -265
- package/src/LineChart/index.ts +750 -766
- package/src/LineChart/types.ts +592 -584
- package/src/PieChart/index.ts +82 -51
- package/src/PieChart/main.ts +71 -71
- package/src/PieChart/types.ts +83 -83
- package/src/PopulationPyramid/index.ts +39 -39
- package/src/PopulationPyramid/types.ts +195 -196
- package/src/components/AnimatedThreeDBar/{index.tsx → index.ts} +18 -18
- package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.ts +97 -93
- package/src/components/BarAndLineChartsWrapper/index.ts +94 -90
- package/src/components/common/StripAndLabel.ts +28 -20
- package/src/components/common/types.ts +31 -0
- package/src/utils/constants.ts +90 -90
- package/src/utils/{index.tsx → index.ts} +720 -636
- package/src/utils/types.ts +352 -351
|
@@ -1,243 +1,262 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ColorValue } from 'react-native'
|
|
2
|
+
import {
|
|
3
|
+
type IDataSanitisationProps,
|
|
4
|
+
type lineDataItem
|
|
5
|
+
} from '../LineChart/types'
|
|
2
6
|
import {
|
|
3
7
|
AxesAndRulesDefaults,
|
|
4
8
|
BarDefaults,
|
|
5
9
|
RANGE_ENTER,
|
|
6
10
|
RANGE_EXIT,
|
|
7
11
|
STOP,
|
|
12
|
+
defaultCurvature,
|
|
8
13
|
defaultLineConfig,
|
|
9
|
-
loc
|
|
10
|
-
} from
|
|
14
|
+
loc
|
|
15
|
+
} from './constants'
|
|
11
16
|
import {
|
|
12
|
-
arrowConfigType,
|
|
17
|
+
type arrowConfigType,
|
|
13
18
|
CurveType,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
type HighlightedRange,
|
|
20
|
+
type LineProperties,
|
|
21
|
+
type LineSegment
|
|
22
|
+
} from './types'
|
|
23
|
+
import {
|
|
24
|
+
type lineConfigType,
|
|
25
|
+
type BarChartPropsType,
|
|
26
|
+
type FocusedBarConfig,
|
|
27
|
+
type barDataItem
|
|
28
|
+
} from '../BarChart/types'
|
|
29
|
+
import { type extendedLineChartPropsType } from '../LineChart'
|
|
30
|
+
import { type extendedBarChartPropsType } from '../BarChart'
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
33
|
+
const versionString = require('react-native/package.json').version
|
|
34
|
+
|
|
35
|
+
const versionAr = versionString?.split?.('.') ?? ''
|
|
36
|
+
const msb = Number(versionAr[0])
|
|
37
|
+
const mid = Number(versionAr[1])
|
|
38
|
+
const lsb = Number(versionAr[2])
|
|
24
39
|
|
|
25
40
|
export const rnVersion =
|
|
26
41
|
(!isNaN(msb) ? msb : 0) * 1000000 +
|
|
27
42
|
(!isNaN(mid) ? mid : 0) * 10000 +
|
|
28
|
-
(!isNaN(lsb) ? lsb : 0)
|
|
43
|
+
(!isNaN(lsb) ? lsb : 0)
|
|
29
44
|
|
|
30
45
|
export const getCumulativeWidth = (
|
|
31
46
|
data: any,
|
|
32
47
|
index: number,
|
|
33
48
|
spacing: number
|
|
34
|
-
) => {
|
|
35
|
-
let cumWidth = 0
|
|
49
|
+
): number => {
|
|
50
|
+
let cumWidth = 0
|
|
36
51
|
for (let i = 0; i < index; i++) {
|
|
37
|
-
let { barWidth } = data[i]
|
|
38
|
-
barWidth = barWidth
|
|
39
|
-
cumWidth += barWidth + (spacing ?? 20)
|
|
52
|
+
let { barWidth } = data[i]
|
|
53
|
+
barWidth = barWidth ?? 30
|
|
54
|
+
cumWidth += barWidth + (spacing ?? 20)
|
|
40
55
|
}
|
|
41
|
-
return cumWidth
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const getLighterColor = (color:
|
|
45
|
-
let r
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (color.startsWith(
|
|
56
|
+
return cumWidth
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const getLighterColor = (color: string): string => {
|
|
60
|
+
let r
|
|
61
|
+
let g
|
|
62
|
+
let b
|
|
63
|
+
let lighter = '#'
|
|
64
|
+
if (color.startsWith('#')) {
|
|
50
65
|
if (color.length < 7) {
|
|
51
|
-
r = parseInt(color[1], 16)
|
|
52
|
-
g = parseInt(color[2], 16)
|
|
53
|
-
b = parseInt(color[3], 16)
|
|
66
|
+
r = parseInt(color[1], 16)
|
|
67
|
+
g = parseInt(color[2], 16)
|
|
68
|
+
b = parseInt(color[3], 16)
|
|
54
69
|
if (r < 14) {
|
|
55
|
-
r += 2
|
|
56
|
-
lighter += r.toString(16)
|
|
70
|
+
r += 2
|
|
71
|
+
lighter += r.toString(16)
|
|
57
72
|
}
|
|
58
73
|
if (g < 14) {
|
|
59
|
-
g += 2
|
|
60
|
-
lighter += g.toString(16)
|
|
74
|
+
g += 2
|
|
75
|
+
lighter += g.toString(16)
|
|
61
76
|
}
|
|
62
77
|
if (b < 14) {
|
|
63
|
-
b += 2
|
|
64
|
-
lighter += b.toString(16)
|
|
78
|
+
b += 2
|
|
79
|
+
lighter += b.toString(16)
|
|
65
80
|
}
|
|
66
81
|
} else {
|
|
67
|
-
r = parseInt(color[1] + color[2], 16)
|
|
68
|
-
g = parseInt(color[3] + color[4], 16)
|
|
69
|
-
b = parseInt(color[5] + color[6], 16)
|
|
82
|
+
r = parseInt(color[1] + color[2], 16)
|
|
83
|
+
g = parseInt(color[3] + color[4], 16)
|
|
84
|
+
b = parseInt(color[5] + color[6], 16)
|
|
70
85
|
|
|
71
86
|
if (r < 224) {
|
|
72
|
-
r += 32
|
|
73
|
-
lighter += r.toString(16)
|
|
87
|
+
r += 32
|
|
88
|
+
lighter += r.toString(16)
|
|
74
89
|
}
|
|
75
90
|
if (g < 224) {
|
|
76
|
-
g += 32
|
|
77
|
-
lighter += g.toString(16)
|
|
91
|
+
g += 32
|
|
92
|
+
lighter += g.toString(16)
|
|
78
93
|
}
|
|
79
94
|
if (b < 224) {
|
|
80
|
-
b += 32
|
|
81
|
-
lighter += b.toString(16)
|
|
95
|
+
b += 32
|
|
96
|
+
lighter += b.toString(16)
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
}
|
|
85
|
-
return lighter
|
|
86
|
-
}
|
|
100
|
+
return lighter
|
|
101
|
+
}
|
|
87
102
|
|
|
88
|
-
export const svgQuadraticCurvePath = (points) => {
|
|
89
|
-
let path =
|
|
103
|
+
export const svgQuadraticCurvePath = (points: number[][]): string => {
|
|
104
|
+
let path = 'M' + points[0][0] + ',' + points[0][1]
|
|
90
105
|
|
|
91
106
|
for (let i = 0; i < points.length - 1; i++) {
|
|
92
|
-
const xMid = (points[i][0] + points[i + 1][0]) / 2
|
|
93
|
-
const yMid = (points[i][1] + points[i + 1][1]) / 2
|
|
94
|
-
const cpX1 = (xMid + points[i][0]) / 2
|
|
95
|
-
const cpX2 = (xMid + points[i + 1][0]) / 2
|
|
107
|
+
const xMid = (points[i][0] + points[i + 1][0]) / 2
|
|
108
|
+
const yMid = (points[i][1] + points[i + 1][1]) / 2
|
|
109
|
+
const cpX1 = (xMid + points[i][0]) / 2
|
|
110
|
+
const cpX2 = (xMid + points[i + 1][0]) / 2
|
|
96
111
|
path +=
|
|
97
|
-
|
|
112
|
+
'Q ' +
|
|
98
113
|
cpX1 +
|
|
99
|
-
|
|
114
|
+
', ' +
|
|
100
115
|
points[i][1] +
|
|
101
|
-
|
|
116
|
+
', ' +
|
|
102
117
|
xMid +
|
|
103
|
-
|
|
118
|
+
', ' +
|
|
104
119
|
yMid +
|
|
105
|
-
(
|
|
120
|
+
(' Q ' +
|
|
106
121
|
cpX2 +
|
|
107
|
-
|
|
122
|
+
', ' +
|
|
108
123
|
points[i + 1][1] +
|
|
109
|
-
|
|
124
|
+
', ' +
|
|
110
125
|
points[i + 1][0] +
|
|
111
|
-
|
|
112
|
-
points[i + 1][1])
|
|
126
|
+
', ' +
|
|
127
|
+
points[i + 1][1])
|
|
113
128
|
}
|
|
114
129
|
|
|
115
|
-
return path
|
|
116
|
-
}
|
|
130
|
+
return path
|
|
131
|
+
}
|
|
117
132
|
|
|
118
133
|
export const svgPath = (
|
|
119
|
-
points:
|
|
120
|
-
curveType
|
|
121
|
-
curvature
|
|
122
|
-
) => {
|
|
123
|
-
if (!points?.length) return
|
|
134
|
+
points: number[][],
|
|
135
|
+
curveType?: CurveType,
|
|
136
|
+
curvature?: number
|
|
137
|
+
): string => {
|
|
138
|
+
if (!points?.length) return ''
|
|
124
139
|
if (curveType === CurveType.QUADRATIC) {
|
|
125
|
-
return svgQuadraticCurvePath(points)
|
|
140
|
+
return svgQuadraticCurvePath(points)
|
|
126
141
|
}
|
|
127
142
|
// build the d attributes by looping over the points
|
|
128
143
|
const d = points.reduce(
|
|
129
144
|
(acc, point, i, a) =>
|
|
130
145
|
i === 0
|
|
131
|
-
?
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
146
|
+
? `M${point[0]},${point[1]}`
|
|
147
|
+
: `${acc} ${bezierCommand(point, i, a, curvature ?? defaultCurvature)}`,
|
|
148
|
+
''
|
|
149
|
+
)
|
|
150
|
+
return d
|
|
151
|
+
}
|
|
152
|
+
interface Iline {
|
|
153
|
+
length: number
|
|
154
|
+
angle: number
|
|
155
|
+
}
|
|
156
|
+
const line = (pointA: number[], pointB: number[]): Iline => {
|
|
157
|
+
const lengthX = pointB[0] - pointA[0]
|
|
158
|
+
const lengthY = pointB[1] - pointA[1]
|
|
143
159
|
return {
|
|
144
160
|
length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)),
|
|
145
|
-
angle: Math.atan2(lengthY, lengthX)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
161
|
+
angle: Math.atan2(lengthY, lengthX)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
148
164
|
|
|
149
165
|
const controlPoint = (
|
|
150
166
|
curvature: number,
|
|
151
|
-
current:
|
|
152
|
-
previous:
|
|
153
|
-
next:
|
|
167
|
+
current: number[],
|
|
168
|
+
previous: number[],
|
|
169
|
+
next: number[],
|
|
154
170
|
reverse?: any
|
|
155
|
-
) => {
|
|
171
|
+
): number[] => {
|
|
156
172
|
// When 'current' is the first or last point of the array
|
|
157
173
|
// 'previous' or 'next' don't exist.
|
|
158
174
|
// Replace with 'current'
|
|
159
|
-
const p = previous
|
|
160
|
-
const n = next
|
|
175
|
+
const p = previous ?? current
|
|
176
|
+
const n = next ?? current
|
|
161
177
|
// The smoothing ratio
|
|
162
|
-
const smoothing = curvature
|
|
178
|
+
const smoothing = curvature
|
|
163
179
|
// Properties of the opposed-line
|
|
164
|
-
const o = line(p, n)
|
|
180
|
+
const o = line(p, n)
|
|
165
181
|
// If is end-control-point, add PI to the angle to go backward
|
|
166
|
-
const angle = o.angle + (reverse ? Math.PI : 0)
|
|
167
|
-
const length = o.length * smoothing
|
|
182
|
+
const angle = o.angle + (reverse ? Math.PI : 0)
|
|
183
|
+
const length = o.length * smoothing
|
|
168
184
|
// The control point position is relative to the current point
|
|
169
|
-
const x = current[0] + Math.cos(angle) * length
|
|
170
|
-
const y = current[1] + Math.sin(angle) * length
|
|
171
|
-
return [x, y]
|
|
172
|
-
}
|
|
185
|
+
const x = current[0] + Math.cos(angle) * length
|
|
186
|
+
const y = current[1] + Math.sin(angle) * length
|
|
187
|
+
return [x, y]
|
|
188
|
+
}
|
|
173
189
|
|
|
174
190
|
export const bezierCommand = (
|
|
175
|
-
point:
|
|
191
|
+
point: number[],
|
|
176
192
|
i: number,
|
|
177
|
-
a:
|
|
193
|
+
a: number[][],
|
|
178
194
|
curvature: number
|
|
179
|
-
) => {
|
|
195
|
+
): string => {
|
|
180
196
|
// start control point
|
|
181
|
-
const [cpsX, cpsY] = controlPoint(curvature, a[i - 1], a[i - 2], point)
|
|
197
|
+
const [cpsX, cpsY] = controlPoint(curvature, a[i - 1], a[i - 2], point)
|
|
182
198
|
// end control point
|
|
183
|
-
const [cpeX, cpeY] = controlPoint(curvature, point, a[i - 1], a[i + 1], true)
|
|
184
|
-
return `C${cpsX},${cpsY} ${cpeX},${cpeY} ${point[0]},${point[1]}
|
|
185
|
-
}
|
|
199
|
+
const [cpeX, cpeY] = controlPoint(curvature, point, a[i - 1], a[i + 1], true)
|
|
200
|
+
return `C${cpsX},${cpsY} ${cpeX},${cpeY} ${point[0]},${point[1]}`
|
|
201
|
+
}
|
|
186
202
|
|
|
187
203
|
export const getSegmentString = (
|
|
188
|
-
lineSegment,
|
|
189
|
-
index,
|
|
190
|
-
startDelimeter,
|
|
191
|
-
endDelimeter
|
|
192
|
-
) => {
|
|
193
|
-
const segment = lineSegment?.find((segment) => segment.startIndex === index)
|
|
194
|
-
return segment ? startDelimeter + JSON.stringify(segment) + endDelimeter :
|
|
195
|
-
}
|
|
204
|
+
lineSegment: LineSegment[] | undefined,
|
|
205
|
+
index: number,
|
|
206
|
+
startDelimeter: string,
|
|
207
|
+
endDelimeter: string
|
|
208
|
+
): string => {
|
|
209
|
+
const segment = lineSegment?.find((segment) => segment.startIndex === index)
|
|
210
|
+
return segment ? startDelimeter + JSON.stringify(segment) + endDelimeter : ''
|
|
211
|
+
}
|
|
196
212
|
|
|
197
213
|
export const getCurvePathWithSegments = (
|
|
198
214
|
path: string,
|
|
199
215
|
lineSegment: LineSegment[] | undefined,
|
|
200
|
-
startDelimeter,
|
|
201
|
-
endDelimeter
|
|
202
|
-
) => {
|
|
203
|
-
if (!lineSegment?.length) return path
|
|
204
|
-
let newPath =
|
|
205
|
-
const pathArray = path.split(
|
|
216
|
+
startDelimeter: string,
|
|
217
|
+
endDelimeter: string
|
|
218
|
+
): string => {
|
|
219
|
+
if (!lineSegment?.length) return path
|
|
220
|
+
let newPath = ''
|
|
221
|
+
const pathArray = path.split('C')
|
|
206
222
|
for (let i = 0; i < pathArray.length; i++) {
|
|
207
|
-
const segment = lineSegment?.find((segment) => segment.startIndex === i)
|
|
223
|
+
const segment = lineSegment?.find((segment) => segment.startIndex === i)
|
|
208
224
|
newPath +=
|
|
209
|
-
(pathArray[i].startsWith(
|
|
225
|
+
(pathArray[i].startsWith('M') ? '' : 'C') +
|
|
210
226
|
pathArray[i] +
|
|
211
|
-
(segment ? startDelimeter + JSON.stringify(segment) + endDelimeter :
|
|
227
|
+
(segment ? startDelimeter + JSON.stringify(segment) + endDelimeter : '')
|
|
212
228
|
}
|
|
213
|
-
return newPath
|
|
214
|
-
}
|
|
229
|
+
return newPath
|
|
230
|
+
}
|
|
215
231
|
|
|
216
|
-
export const getPreviousSegmentsLastPoint = (
|
|
232
|
+
export const getPreviousSegmentsLastPoint = (
|
|
233
|
+
isCurved: boolean,
|
|
234
|
+
previousSegment: string
|
|
235
|
+
): string => {
|
|
217
236
|
const prevSegmentLastPoint = isCurved
|
|
218
|
-
? previousSegment.substring(previousSegment.trim().lastIndexOf(
|
|
237
|
+
? previousSegment.substring(previousSegment.trim().lastIndexOf(' '))
|
|
219
238
|
: previousSegment
|
|
220
|
-
.substring(previousSegment.lastIndexOf(
|
|
221
|
-
.replace(
|
|
239
|
+
.substring(previousSegment.lastIndexOf('L'))
|
|
240
|
+
.replace('L', 'M')
|
|
222
241
|
|
|
223
242
|
return (
|
|
224
|
-
(prevSegmentLastPoint.trim()[0] ===
|
|
225
|
-
)
|
|
226
|
-
}
|
|
243
|
+
(prevSegmentLastPoint.trim()[0] === 'M' ? '' : 'M') + prevSegmentLastPoint
|
|
244
|
+
)
|
|
245
|
+
}
|
|
227
246
|
|
|
228
247
|
export const getPathWithHighlight = (
|
|
229
|
-
data,
|
|
230
|
-
i,
|
|
231
|
-
highlightedRange,
|
|
232
|
-
startIndex,
|
|
233
|
-
endIndex,
|
|
234
|
-
getX,
|
|
235
|
-
getY
|
|
236
|
-
) => {
|
|
237
|
-
let path =
|
|
238
|
-
const { from, to } = highlightedRange
|
|
248
|
+
data: lineDataItem[],
|
|
249
|
+
i: number,
|
|
250
|
+
highlightedRange: HighlightedRange,
|
|
251
|
+
startIndex: number,
|
|
252
|
+
endIndex: number,
|
|
253
|
+
getX: (i: number) => number,
|
|
254
|
+
getY: (value: number) => number
|
|
255
|
+
): string => {
|
|
256
|
+
let path = ''
|
|
257
|
+
const { from, to } = highlightedRange
|
|
239
258
|
const currentPointRegion =
|
|
240
|
-
data[i].value < from ? loc.DOWN : data[i].value > to ? loc.UP : loc.IN
|
|
259
|
+
data[i].value < from ? loc.DOWN : data[i].value > to ? loc.UP : loc.IN
|
|
241
260
|
|
|
242
261
|
if (i !== endIndex) {
|
|
243
262
|
const nextPointRegion =
|
|
@@ -245,351 +264,354 @@ export const getPathWithHighlight = (
|
|
|
245
264
|
? loc.DOWN
|
|
246
265
|
: data[i + 1].value > to
|
|
247
266
|
? loc.UP
|
|
248
|
-
: loc.IN
|
|
267
|
+
: loc.IN
|
|
249
268
|
if (
|
|
250
269
|
currentPointRegion !== nextPointRegion ||
|
|
251
270
|
(i === startIndex && currentPointRegion === loc.IN)
|
|
252
271
|
) {
|
|
253
|
-
const x1 = getX(i)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
let m = (y2 - y1) / (x2 - x1)
|
|
259
|
-
|
|
260
|
-
|
|
272
|
+
const x1 = getX(i)
|
|
273
|
+
const y1 = getY(data[i].value)
|
|
274
|
+
const x2 = getX(i + 1)
|
|
275
|
+
const y2 = getY(data[i + 1].value)
|
|
276
|
+
|
|
277
|
+
let m = (y2 - y1) / (x2 - x1)
|
|
278
|
+
let x = 0
|
|
279
|
+
let y = 0
|
|
261
280
|
if (i === startIndex && currentPointRegion === loc.IN) {
|
|
262
281
|
// If the 1st point lies IN
|
|
263
|
-
y = y1
|
|
264
|
-
x = x1
|
|
282
|
+
y = y1
|
|
283
|
+
x = x1
|
|
265
284
|
|
|
266
285
|
path +=
|
|
267
|
-
|
|
286
|
+
'L' +
|
|
268
287
|
x +
|
|
269
|
-
|
|
288
|
+
' ' +
|
|
270
289
|
y +
|
|
271
|
-
|
|
290
|
+
' ' +
|
|
272
291
|
RANGE_ENTER +
|
|
273
292
|
JSON.stringify(highlightedRange) +
|
|
274
|
-
STOP
|
|
293
|
+
STOP
|
|
275
294
|
|
|
276
295
|
if (nextPointRegion === loc.UP) {
|
|
277
|
-
y = getY(to)
|
|
278
|
-
x = (y - y1) / m + x1
|
|
296
|
+
y = getY(to)
|
|
297
|
+
x = (y - y1) / m + x1
|
|
279
298
|
|
|
280
|
-
path +=
|
|
299
|
+
path += 'L' + x + ' ' + y + ' ' + RANGE_EXIT
|
|
281
300
|
} else if (nextPointRegion === loc.DOWN) {
|
|
282
|
-
y = getY(from)
|
|
283
|
-
x = (y - y1) / m + x1
|
|
301
|
+
y = getY(from)
|
|
302
|
+
x = (y - y1) / m + x1
|
|
284
303
|
|
|
285
|
-
path +=
|
|
304
|
+
path += 'L' + x + ' ' + y + ' ' + RANGE_EXIT
|
|
286
305
|
}
|
|
287
306
|
} else if (currentPointRegion !== nextPointRegion) {
|
|
288
307
|
if (currentPointRegion === loc.DOWN && nextPointRegion === loc.UP) {
|
|
289
308
|
// if current point is in DOWN and next point is in UP, then we will add 2 points to the the path
|
|
290
|
-
y = getY(from)
|
|
291
|
-
x = (y - y1) / m + x1
|
|
309
|
+
y = getY(from)
|
|
310
|
+
x = (y - y1) / m + x1
|
|
292
311
|
|
|
293
312
|
path +=
|
|
294
|
-
|
|
313
|
+
'L' +
|
|
295
314
|
x +
|
|
296
|
-
|
|
315
|
+
' ' +
|
|
297
316
|
y +
|
|
298
|
-
|
|
317
|
+
' ' +
|
|
299
318
|
RANGE_ENTER +
|
|
300
319
|
JSON.stringify(highlightedRange) +
|
|
301
|
-
STOP
|
|
302
|
-
y = getY(to)
|
|
303
|
-
x = (y - y1) / m + x1
|
|
320
|
+
STOP
|
|
321
|
+
y = getY(to)
|
|
322
|
+
x = (y - y1) / m + x1
|
|
304
323
|
|
|
305
|
-
path +=
|
|
324
|
+
path += 'L' + x + ' ' + y + ' ' + RANGE_EXIT
|
|
306
325
|
} else if (
|
|
307
326
|
currentPointRegion === loc.UP &&
|
|
308
327
|
nextPointRegion === loc.DOWN
|
|
309
328
|
) {
|
|
310
329
|
// if current point is in UP and next point is in DOWN, then we will add 2 points to the the path
|
|
311
|
-
y = getY(to)
|
|
312
|
-
x = (y - y1) / m + x1
|
|
330
|
+
y = getY(to)
|
|
331
|
+
x = (y - y1) / m + x1
|
|
313
332
|
|
|
314
333
|
path +=
|
|
315
|
-
|
|
334
|
+
'L' +
|
|
316
335
|
x +
|
|
317
|
-
|
|
336
|
+
' ' +
|
|
318
337
|
y +
|
|
319
|
-
|
|
338
|
+
' ' +
|
|
320
339
|
RANGE_ENTER +
|
|
321
340
|
JSON.stringify(highlightedRange) +
|
|
322
|
-
STOP
|
|
323
|
-
y = getY(from)
|
|
324
|
-
x = (y - y1) / m + x1
|
|
341
|
+
STOP
|
|
342
|
+
y = getY(from)
|
|
343
|
+
x = (y - y1) / m + x1
|
|
325
344
|
|
|
326
|
-
path +=
|
|
345
|
+
path += 'L' + x + ' ' + y + ' ' + RANGE_EXIT
|
|
327
346
|
} else {
|
|
328
347
|
if (
|
|
329
348
|
(currentPointRegion === loc.UP && nextPointRegion === loc.IN) ||
|
|
330
349
|
(currentPointRegion === loc.IN && nextPointRegion === loc.UP)
|
|
331
350
|
) {
|
|
332
|
-
y = getY(to)
|
|
351
|
+
y = getY(to)
|
|
333
352
|
} else if (
|
|
334
353
|
(currentPointRegion === loc.IN && nextPointRegion === loc.DOWN) ||
|
|
335
354
|
(currentPointRegion === loc.DOWN && nextPointRegion === loc.IN)
|
|
336
355
|
) {
|
|
337
|
-
y = getY(from)
|
|
356
|
+
y = getY(from)
|
|
338
357
|
}
|
|
339
|
-
m = (y2 - y1) / (x2 - x1)
|
|
340
|
-
x = (y - y1) / m + x1
|
|
358
|
+
m = (y2 - y1) / (x2 - x1)
|
|
359
|
+
x = (y - y1) / m + x1
|
|
341
360
|
|
|
342
361
|
const prefix =
|
|
343
362
|
nextPointRegion === loc.IN
|
|
344
363
|
? RANGE_ENTER + JSON.stringify(highlightedRange) + STOP
|
|
345
|
-
: RANGE_EXIT
|
|
364
|
+
: RANGE_EXIT
|
|
346
365
|
|
|
347
|
-
path +=
|
|
366
|
+
path += 'L' + x + ' ' + y + ' ' + prefix
|
|
348
367
|
}
|
|
349
368
|
}
|
|
350
369
|
}
|
|
351
370
|
} else if (currentPointRegion === loc.IN) {
|
|
352
371
|
// If the last point lies IN, add RANGE_EXIT
|
|
353
|
-
path += RANGE_EXIT
|
|
372
|
+
path += RANGE_EXIT
|
|
354
373
|
}
|
|
355
374
|
|
|
356
|
-
return path
|
|
357
|
-
}
|
|
375
|
+
return path
|
|
376
|
+
}
|
|
358
377
|
|
|
359
378
|
export const getRegionPathObjects = (
|
|
360
|
-
points,
|
|
361
|
-
color,
|
|
362
|
-
currentLineThickness,
|
|
363
|
-
thickness,
|
|
364
|
-
strokeDashArray,
|
|
365
|
-
isCurved,
|
|
366
|
-
startDelimeter,
|
|
367
|
-
stop,
|
|
368
|
-
endDelimeter
|
|
369
|
-
) => {
|
|
370
|
-
const ar: [
|
|
371
|
-
let tempStr = points
|
|
379
|
+
points: string,
|
|
380
|
+
color: ColorValue,
|
|
381
|
+
currentLineThickness: number,
|
|
382
|
+
thickness: number,
|
|
383
|
+
strokeDashArray: number[],
|
|
384
|
+
isCurved: boolean,
|
|
385
|
+
startDelimeter: string,
|
|
386
|
+
stop: string,
|
|
387
|
+
endDelimeter: string
|
|
388
|
+
): LineProperties[] => {
|
|
389
|
+
const ar: [LineProperties] = [{ d: '', color: '', strokeWidth: 0 }]
|
|
390
|
+
let tempStr = points
|
|
372
391
|
|
|
373
392
|
if (!points.startsWith(startDelimeter)) {
|
|
374
|
-
|
|
393
|
+
/** ******************** line upto first segment *****************/
|
|
375
394
|
|
|
376
395
|
const lineSvgProps: LineProperties = {
|
|
377
396
|
d: points.substring(0, points.indexOf(startDelimeter)),
|
|
378
397
|
color,
|
|
379
|
-
strokeWidth: currentLineThickness || thickness
|
|
380
|
-
}
|
|
398
|
+
strokeWidth: currentLineThickness || thickness
|
|
399
|
+
}
|
|
381
400
|
if (strokeDashArray) {
|
|
382
|
-
lineSvgProps.strokeDashArray = strokeDashArray
|
|
401
|
+
lineSvgProps.strokeDashArray = strokeDashArray
|
|
383
402
|
}
|
|
384
|
-
ar.push(lineSvgProps)
|
|
403
|
+
ar.push(lineSvgProps)
|
|
385
404
|
}
|
|
386
405
|
|
|
387
406
|
while (tempStr.includes(startDelimeter)) {
|
|
388
|
-
const startDelimeterIndex = tempStr.indexOf(startDelimeter)
|
|
389
|
-
const stopIndex = tempStr.indexOf(stop)
|
|
390
|
-
const endDelimeterIndex = tempStr.indexOf(endDelimeter)
|
|
407
|
+
const startDelimeterIndex = tempStr.indexOf(startDelimeter)
|
|
408
|
+
const stopIndex = tempStr.indexOf(stop)
|
|
409
|
+
const endDelimeterIndex = tempStr.indexOf(endDelimeter)
|
|
391
410
|
|
|
392
411
|
const segmentConfigString = tempStr.substring(
|
|
393
412
|
startDelimeterIndex + startDelimeter.length,
|
|
394
413
|
stopIndex
|
|
395
|
-
)
|
|
414
|
+
)
|
|
396
415
|
|
|
397
|
-
const segmentConfig = JSON.parse(segmentConfigString)
|
|
416
|
+
const segmentConfig = JSON.parse(segmentConfigString)
|
|
398
417
|
|
|
399
|
-
|
|
418
|
+
const segment = tempStr.substring(
|
|
419
|
+
stopIndex + stop.length,
|
|
420
|
+
endDelimeterIndex
|
|
421
|
+
)
|
|
400
422
|
|
|
401
|
-
const previousSegment = ar[ar.length - 1].d
|
|
423
|
+
const previousSegment = ar[ar.length - 1].d
|
|
402
424
|
const moveToLastPointOfPreviousSegment = getPreviousSegmentsLastPoint(
|
|
403
425
|
isCurved,
|
|
404
426
|
previousSegment
|
|
405
|
-
)
|
|
427
|
+
)
|
|
406
428
|
|
|
407
|
-
|
|
429
|
+
/** ******************** segment line *****************/
|
|
408
430
|
|
|
409
431
|
const lineSvgProps: LineProperties = {
|
|
410
432
|
d: moveToLastPointOfPreviousSegment + segment,
|
|
411
433
|
color: segmentConfig.color ?? color,
|
|
412
434
|
strokeWidth:
|
|
413
|
-
segmentConfig.thickness ?? (currentLineThickness || thickness)
|
|
414
|
-
}
|
|
435
|
+
segmentConfig.thickness ?? (currentLineThickness || thickness)
|
|
436
|
+
}
|
|
415
437
|
if (segmentConfig.strokeDashArray) {
|
|
416
|
-
lineSvgProps.strokeDashArray = segmentConfig.strokeDashArray
|
|
438
|
+
lineSvgProps.strokeDashArray = segmentConfig.strokeDashArray
|
|
417
439
|
}
|
|
418
|
-
ar.push(lineSvgProps)
|
|
440
|
+
ar.push(lineSvgProps)
|
|
419
441
|
|
|
420
|
-
tempStr = tempStr.substring(endDelimeterIndex + endDelimeter.length)
|
|
442
|
+
tempStr = tempStr.substring(endDelimeterIndex + endDelimeter.length)
|
|
421
443
|
|
|
422
|
-
const nextDelimiterIndex = tempStr.indexOf(startDelimeter)
|
|
423
|
-
const stringUptoNextSegment = tempStr.substring(0, nextDelimiterIndex)
|
|
444
|
+
const nextDelimiterIndex = tempStr.indexOf(startDelimeter)
|
|
445
|
+
const stringUptoNextSegment = tempStr.substring(0, nextDelimiterIndex)
|
|
424
446
|
|
|
425
|
-
|
|
447
|
+
/** ******************** line upto the next segment *****************/
|
|
426
448
|
|
|
427
449
|
if (
|
|
428
450
|
nextDelimiterIndex !== -1 &&
|
|
429
|
-
stringUptoNextSegment.
|
|
451
|
+
stringUptoNextSegment.includes(isCurved ? 'C' : 'L')
|
|
430
452
|
) {
|
|
431
|
-
const previousSegment = ar[ar.length - 1].d
|
|
453
|
+
const previousSegment = ar[ar.length - 1].d
|
|
432
454
|
const moveToLastPointOfPreviousSegment = getPreviousSegmentsLastPoint(
|
|
433
455
|
isCurved,
|
|
434
456
|
previousSegment
|
|
435
|
-
)
|
|
457
|
+
)
|
|
436
458
|
const lineSvgProps: LineProperties = {
|
|
437
|
-
d: moveToLastPointOfPreviousSegment +
|
|
459
|
+
d: moveToLastPointOfPreviousSegment + ' ' + stringUptoNextSegment,
|
|
438
460
|
color,
|
|
439
|
-
strokeWidth: currentLineThickness || thickness
|
|
440
|
-
}
|
|
461
|
+
strokeWidth: currentLineThickness || thickness
|
|
462
|
+
}
|
|
441
463
|
if (strokeDashArray) {
|
|
442
|
-
lineSvgProps.strokeDashArray = strokeDashArray
|
|
464
|
+
lineSvgProps.strokeDashArray = strokeDashArray
|
|
443
465
|
}
|
|
444
|
-
ar.push(lineSvgProps)
|
|
466
|
+
ar.push(lineSvgProps)
|
|
445
467
|
}
|
|
446
468
|
}
|
|
447
469
|
|
|
448
|
-
|
|
470
|
+
/** ******************** line after the last segment *****************/
|
|
449
471
|
|
|
450
472
|
if (tempStr.length) {
|
|
451
|
-
const previousSegment = ar[ar.length - 1].d
|
|
473
|
+
const previousSegment = ar[ar.length - 1].d
|
|
452
474
|
const moveToLastPointOfPreviousSegment = getPreviousSegmentsLastPoint(
|
|
453
475
|
isCurved,
|
|
454
476
|
previousSegment
|
|
455
|
-
)
|
|
477
|
+
)
|
|
456
478
|
const lineSvgProps: LineProperties = {
|
|
457
479
|
d: moveToLastPointOfPreviousSegment + tempStr,
|
|
458
480
|
color,
|
|
459
|
-
strokeWidth: currentLineThickness || thickness
|
|
460
|
-
}
|
|
481
|
+
strokeWidth: currentLineThickness || thickness
|
|
482
|
+
}
|
|
461
483
|
if (strokeDashArray) {
|
|
462
|
-
lineSvgProps.strokeDashArray = strokeDashArray
|
|
484
|
+
lineSvgProps.strokeDashArray = strokeDashArray
|
|
463
485
|
}
|
|
464
|
-
ar.push(lineSvgProps)
|
|
486
|
+
ar.push(lineSvgProps)
|
|
465
487
|
}
|
|
466
488
|
|
|
467
|
-
ar.shift()
|
|
468
|
-
return ar
|
|
469
|
-
}
|
|
489
|
+
ar.shift()
|
|
490
|
+
return ar
|
|
491
|
+
}
|
|
470
492
|
|
|
471
493
|
export const getSegmentedPathObjects = (
|
|
472
|
-
points,
|
|
473
|
-
color,
|
|
474
|
-
currentLineThickness,
|
|
475
|
-
thickness,
|
|
476
|
-
strokeDashArray,
|
|
477
|
-
isCurved,
|
|
478
|
-
startDelimeter,
|
|
479
|
-
endDelimeter
|
|
480
|
-
) => {
|
|
481
|
-
const ar: [
|
|
482
|
-
let tempStr = points
|
|
494
|
+
points: string,
|
|
495
|
+
color: ColorValue,
|
|
496
|
+
currentLineThickness: number,
|
|
497
|
+
thickness: number,
|
|
498
|
+
strokeDashArray: number[],
|
|
499
|
+
isCurved: boolean,
|
|
500
|
+
startDelimeter: string,
|
|
501
|
+
endDelimeter: string
|
|
502
|
+
): LineProperties[] => {
|
|
503
|
+
const ar: [LineProperties] = [{ d: '', color: '', strokeWidth: 0 }]
|
|
504
|
+
let tempStr = points
|
|
483
505
|
|
|
484
506
|
if (!points.startsWith(startDelimeter)) {
|
|
485
|
-
|
|
507
|
+
/** ******************** line upto first segment *****************/
|
|
486
508
|
|
|
487
509
|
const lineSvgProps: LineProperties = {
|
|
488
510
|
d: points.substring(0, points.indexOf(startDelimeter)),
|
|
489
511
|
color,
|
|
490
|
-
strokeWidth: currentLineThickness || thickness
|
|
491
|
-
}
|
|
512
|
+
strokeWidth: currentLineThickness || thickness
|
|
513
|
+
}
|
|
492
514
|
if (strokeDashArray) {
|
|
493
|
-
lineSvgProps.strokeDashArray = strokeDashArray
|
|
515
|
+
lineSvgProps.strokeDashArray = strokeDashArray
|
|
494
516
|
}
|
|
495
|
-
ar.push(lineSvgProps)
|
|
517
|
+
ar.push(lineSvgProps)
|
|
496
518
|
}
|
|
497
519
|
|
|
498
520
|
while (tempStr.includes(startDelimeter)) {
|
|
499
|
-
const startDelimeterIndex = tempStr.indexOf(startDelimeter)
|
|
500
|
-
const endDelimeterIndex = tempStr.indexOf(endDelimeter)
|
|
521
|
+
const startDelimeterIndex = tempStr.indexOf(startDelimeter)
|
|
522
|
+
const endDelimeterIndex = tempStr.indexOf(endDelimeter)
|
|
501
523
|
|
|
502
524
|
const segmentConfigString = tempStr.substring(
|
|
503
525
|
startDelimeterIndex + startDelimeter.length,
|
|
504
526
|
endDelimeterIndex
|
|
505
|
-
)
|
|
527
|
+
)
|
|
506
528
|
|
|
507
|
-
const segmentConfig = JSON.parse(segmentConfigString)
|
|
529
|
+
const segmentConfig = JSON.parse(segmentConfigString)
|
|
508
530
|
|
|
509
|
-
const { startIndex, endIndex } = segmentConfig
|
|
510
|
-
const segmentLength = endIndex - startIndex
|
|
511
|
-
let segment = tempStr.substring(endDelimeterIndex + endDelimeter.length)
|
|
512
|
-
let c = 0
|
|
513
|
-
|
|
514
|
-
|
|
531
|
+
const { startIndex, endIndex } = segmentConfig
|
|
532
|
+
const segmentLength = endIndex - startIndex
|
|
533
|
+
let segment = tempStr.substring(endDelimeterIndex + endDelimeter.length)
|
|
534
|
+
let c = 0
|
|
535
|
+
let s = 0
|
|
536
|
+
let i
|
|
515
537
|
for (i = 0; i < segment.length; i++) {
|
|
516
|
-
if (segment[i] === (isCurved ?
|
|
538
|
+
if (segment[i] === (isCurved ? 'C' : 'L')) c++
|
|
517
539
|
if (c === segmentLength) {
|
|
518
|
-
if (segment[i] ===
|
|
519
|
-
if (s === (isCurved ? 3 : 2)) break
|
|
540
|
+
if (segment[i] === ' ') s++
|
|
541
|
+
if (s === (isCurved ? 3 : 2)) break
|
|
520
542
|
}
|
|
521
543
|
}
|
|
522
|
-
segment = segment.substring(0, i)
|
|
544
|
+
segment = segment.substring(0, i)
|
|
523
545
|
|
|
524
|
-
const previousSegment = ar[ar.length - 1].d
|
|
546
|
+
const previousSegment = ar[ar.length - 1].d
|
|
525
547
|
const moveToLastPointOfPreviousSegment = getPreviousSegmentsLastPoint(
|
|
526
548
|
isCurved,
|
|
527
549
|
previousSegment
|
|
528
|
-
)
|
|
550
|
+
)
|
|
529
551
|
|
|
530
|
-
|
|
552
|
+
/** ******************** segment line *****************/
|
|
531
553
|
|
|
532
554
|
const lineSvgProps: LineProperties = {
|
|
533
555
|
d: moveToLastPointOfPreviousSegment + segment,
|
|
534
556
|
color: segmentConfig.color ?? color,
|
|
535
557
|
strokeWidth:
|
|
536
|
-
segmentConfig.thickness ?? (currentLineThickness || thickness)
|
|
537
|
-
}
|
|
558
|
+
segmentConfig.thickness ?? (currentLineThickness || thickness)
|
|
559
|
+
}
|
|
538
560
|
if (segmentConfig.strokeDashArray) {
|
|
539
|
-
lineSvgProps.strokeDashArray = segmentConfig.strokeDashArray
|
|
561
|
+
lineSvgProps.strokeDashArray = segmentConfig.strokeDashArray
|
|
540
562
|
}
|
|
541
|
-
ar.push(lineSvgProps)
|
|
563
|
+
ar.push(lineSvgProps)
|
|
542
564
|
|
|
543
|
-
tempStr = tempStr.substring(endDelimeterIndex + endDelimeter.length + i)
|
|
565
|
+
tempStr = tempStr.substring(endDelimeterIndex + endDelimeter.length + i)
|
|
544
566
|
|
|
545
|
-
const nextDelimiterIndex = tempStr.indexOf(startDelimeter)
|
|
546
|
-
const stringUptoNextSegment = tempStr.substring(0, nextDelimiterIndex)
|
|
567
|
+
const nextDelimiterIndex = tempStr.indexOf(startDelimeter)
|
|
568
|
+
const stringUptoNextSegment = tempStr.substring(0, nextDelimiterIndex)
|
|
547
569
|
|
|
548
|
-
|
|
570
|
+
/** ******************** line upto the next segment *****************/
|
|
549
571
|
|
|
550
572
|
if (
|
|
551
573
|
nextDelimiterIndex !== -1 &&
|
|
552
|
-
stringUptoNextSegment.
|
|
574
|
+
stringUptoNextSegment.includes(isCurved ? 'C' : 'L')
|
|
553
575
|
) {
|
|
554
|
-
const previousSegment = ar[ar.length - 1].d
|
|
576
|
+
const previousSegment = ar[ar.length - 1].d
|
|
555
577
|
const moveToLastPointOfPreviousSegment = getPreviousSegmentsLastPoint(
|
|
556
578
|
isCurved,
|
|
557
579
|
previousSegment
|
|
558
|
-
)
|
|
580
|
+
)
|
|
559
581
|
const lineSvgProps: LineProperties = {
|
|
560
|
-
d: moveToLastPointOfPreviousSegment +
|
|
582
|
+
d: moveToLastPointOfPreviousSegment + ' ' + stringUptoNextSegment,
|
|
561
583
|
color,
|
|
562
|
-
strokeWidth: currentLineThickness || thickness
|
|
563
|
-
}
|
|
584
|
+
strokeWidth: currentLineThickness || thickness
|
|
585
|
+
}
|
|
564
586
|
if (strokeDashArray) {
|
|
565
|
-
lineSvgProps.strokeDashArray = strokeDashArray
|
|
587
|
+
lineSvgProps.strokeDashArray = strokeDashArray
|
|
566
588
|
}
|
|
567
|
-
ar.push(lineSvgProps)
|
|
589
|
+
ar.push(lineSvgProps)
|
|
568
590
|
}
|
|
569
591
|
}
|
|
570
592
|
|
|
571
|
-
|
|
593
|
+
/** ******************** line after the last segment *****************/
|
|
572
594
|
|
|
573
595
|
if (tempStr.length) {
|
|
574
|
-
const previousSegment = ar[ar.length - 1].d
|
|
596
|
+
const previousSegment = ar[ar.length - 1].d
|
|
575
597
|
const moveToLastPointOfPreviousSegment = getPreviousSegmentsLastPoint(
|
|
576
598
|
isCurved,
|
|
577
599
|
previousSegment
|
|
578
|
-
)
|
|
600
|
+
)
|
|
579
601
|
const lineSvgProps: LineProperties = {
|
|
580
602
|
d: moveToLastPointOfPreviousSegment + tempStr,
|
|
581
603
|
color,
|
|
582
|
-
strokeWidth: currentLineThickness || thickness
|
|
583
|
-
}
|
|
604
|
+
strokeWidth: currentLineThickness || thickness
|
|
605
|
+
}
|
|
584
606
|
if (strokeDashArray) {
|
|
585
|
-
lineSvgProps.strokeDashArray = strokeDashArray
|
|
607
|
+
lineSvgProps.strokeDashArray = strokeDashArray
|
|
586
608
|
}
|
|
587
|
-
ar.push(lineSvgProps)
|
|
609
|
+
ar.push(lineSvgProps)
|
|
588
610
|
}
|
|
589
611
|
|
|
590
|
-
ar.shift()
|
|
591
|
-
return ar
|
|
592
|
-
}
|
|
612
|
+
ar.shift()
|
|
613
|
+
return ar
|
|
614
|
+
}
|
|
593
615
|
|
|
594
616
|
export const getArrowPoints = (
|
|
595
617
|
arrowTipX: number,
|
|
@@ -599,49 +621,55 @@ export const getArrowPoints = (
|
|
|
599
621
|
arrowLength?: number,
|
|
600
622
|
arrowWidth?: number,
|
|
601
623
|
showArrowBase?: boolean
|
|
602
|
-
) => {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
arrowTipX - Math.sqrt((d * d) / (dataLineSlope * dataLineSlope + 1))
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
let arrowBasex1, arrowBaseY1, arrowBaseX2, arrowBaseY2
|
|
624
|
+
): string => {
|
|
625
|
+
const dataLineSlope = (arrowTipY - y1) / (arrowTipX - x1)
|
|
626
|
+
const d = arrowLength ?? 0
|
|
627
|
+
const d2 = (arrowWidth ?? 0) / 2
|
|
628
|
+
const interSectionX =
|
|
629
|
+
arrowTipX - Math.sqrt((d * d) / (dataLineSlope * dataLineSlope + 1))
|
|
630
|
+
const interSectionY = arrowTipY - dataLineSlope * (arrowTipX - interSectionX)
|
|
631
|
+
|
|
632
|
+
let arrowBasex1, arrowBaseY1, arrowBaseX2, arrowBaseY2
|
|
611
633
|
if (dataLineSlope === 0) {
|
|
612
|
-
arrowBasex1 = interSectionX
|
|
613
|
-
arrowBaseY1 = interSectionY - d2
|
|
614
|
-
arrowBaseX2 = interSectionX
|
|
615
|
-
arrowBaseY2 = interSectionY + d2
|
|
634
|
+
arrowBasex1 = interSectionX
|
|
635
|
+
arrowBaseY1 = interSectionY - d2
|
|
636
|
+
arrowBaseX2 = interSectionX
|
|
637
|
+
arrowBaseY2 = interSectionY + d2
|
|
616
638
|
} else {
|
|
617
|
-
|
|
639
|
+
const arrowBaseSlope = -1 / dataLineSlope
|
|
618
640
|
arrowBasex1 =
|
|
619
641
|
interSectionX -
|
|
620
|
-
Math.sqrt((d2 * d2) / (arrowBaseSlope * arrowBaseSlope + 1))
|
|
621
|
-
arrowBaseY1 =
|
|
622
|
-
interSectionY - arrowBaseSlope * (interSectionX - arrowBasex1);
|
|
642
|
+
Math.sqrt((d2 * d2) / (arrowBaseSlope * arrowBaseSlope + 1))
|
|
643
|
+
arrowBaseY1 = interSectionY - arrowBaseSlope * (interSectionX - arrowBasex1)
|
|
623
644
|
|
|
624
645
|
arrowBaseX2 =
|
|
625
646
|
interSectionX +
|
|
626
|
-
Math.sqrt((d2 * d2) / (arrowBaseSlope * arrowBaseSlope + 1))
|
|
627
|
-
arrowBaseY2 =
|
|
628
|
-
interSectionY + arrowBaseSlope * (interSectionX - arrowBasex1);
|
|
647
|
+
Math.sqrt((d2 * d2) / (arrowBaseSlope * arrowBaseSlope + 1))
|
|
648
|
+
arrowBaseY2 = interSectionY + arrowBaseSlope * (interSectionX - arrowBasex1)
|
|
629
649
|
}
|
|
630
|
-
let arrowPoints = ` M${interSectionX} ${interSectionY}
|
|
631
|
-
arrowPoints += ` ${showArrowBase ?
|
|
632
|
-
arrowPoints += ` L${arrowTipX} ${arrowTipY}
|
|
633
|
-
arrowPoints += ` M${interSectionX} ${interSectionY}
|
|
634
|
-
arrowPoints += ` ${showArrowBase ?
|
|
635
|
-
arrowPoints += ` L${arrowTipX} ${arrowTipY}
|
|
650
|
+
let arrowPoints = ` M${interSectionX} ${interSectionY}`
|
|
651
|
+
arrowPoints += ` ${showArrowBase ? 'L' : 'M'}${arrowBasex1} ${arrowBaseY1}`
|
|
652
|
+
arrowPoints += ` L${arrowTipX} ${arrowTipY}`
|
|
653
|
+
arrowPoints += ` M${interSectionX} ${interSectionY}`
|
|
654
|
+
arrowPoints += ` ${showArrowBase ? 'L' : 'M'}${arrowBaseX2} ${arrowBaseY2}`
|
|
655
|
+
arrowPoints += ` L${arrowTipX} ${arrowTipY}`
|
|
656
|
+
|
|
657
|
+
return arrowPoints
|
|
658
|
+
}
|
|
636
659
|
|
|
637
|
-
|
|
638
|
-
|
|
660
|
+
interface IgetAxesAndRulesProps extends BarChartPropsType {
|
|
661
|
+
verticalLinesUptoDataPoint?: boolean
|
|
662
|
+
}
|
|
639
663
|
|
|
640
664
|
export const getAxesAndRulesProps = (
|
|
641
|
-
props:
|
|
665
|
+
props: extendedBarChartPropsType,
|
|
642
666
|
stepValue: number,
|
|
643
667
|
maxValue?: number
|
|
644
|
-
) => {
|
|
668
|
+
): IgetAxesAndRulesProps => {
|
|
669
|
+
const secondaryYAxis =
|
|
670
|
+
!props.secondaryYAxis || props.secondaryYAxis === true
|
|
671
|
+
? {}
|
|
672
|
+
: props.secondaryYAxis
|
|
645
673
|
const axesAndRulesProps = {
|
|
646
674
|
yAxisSide: props.yAxisSide,
|
|
647
675
|
yAxisLabelContainerStyle: props.yAxisLabelContainerStyle,
|
|
@@ -686,7 +714,7 @@ export const getAxesAndRulesProps = (
|
|
|
686
714
|
showReferenceLine3: props.showReferenceLine3,
|
|
687
715
|
referenceLine3Position: props.referenceLine3Position,
|
|
688
716
|
referenceLine3Config: props.referenceLine3Config,
|
|
689
|
-
referenceLinesOverChartContent: props.referenceLinesOverChartContent
|
|
717
|
+
referenceLinesOverChartContent: props.referenceLinesOverChartContent
|
|
690
718
|
},
|
|
691
719
|
|
|
692
720
|
showVerticalLines: props.showVerticalLines,
|
|
@@ -698,223 +726,263 @@ export const getAxesAndRulesProps = (
|
|
|
698
726
|
verticalLinesSpacing: props.verticalLinesSpacing,
|
|
699
727
|
noOfVerticalLines: props.noOfVerticalLines,
|
|
700
728
|
|
|
701
|
-
//specific to Line charts-
|
|
729
|
+
// specific to Line charts-
|
|
702
730
|
verticalLinesUptoDataPoint: props.verticalLinesUptoDataPoint,
|
|
703
731
|
|
|
704
732
|
roundToDigits: props.roundToDigits,
|
|
705
733
|
stepValue,
|
|
706
734
|
|
|
707
735
|
secondaryYAxis: props.secondaryYAxis,
|
|
708
|
-
formatYLabel: props.formatYLabel
|
|
709
|
-
}
|
|
736
|
+
formatYLabel: props.formatYLabel
|
|
737
|
+
}
|
|
710
738
|
if (
|
|
711
|
-
(props.secondaryYAxis
|
|
739
|
+
(props.secondaryYAxis ?? props.lineConfig?.isSecondary) &&
|
|
712
740
|
maxValue !== undefined
|
|
713
741
|
) {
|
|
714
|
-
axesAndRulesProps.secondaryYAxis = { ...
|
|
742
|
+
axesAndRulesProps.secondaryYAxis = { ...secondaryYAxis, maxValue }
|
|
715
743
|
}
|
|
716
744
|
|
|
717
|
-
return axesAndRulesProps
|
|
718
|
-
}
|
|
745
|
+
return axesAndRulesProps
|
|
746
|
+
}
|
|
719
747
|
|
|
720
748
|
export const getExtendedContainerHeightWithPadding = (
|
|
721
749
|
containerHeight: number,
|
|
722
750
|
overflowTop?: number
|
|
723
|
-
) => containerHeight + (overflowTop ?? 0) + 10
|
|
751
|
+
): number => containerHeight + (overflowTop ?? 0) + 10
|
|
724
752
|
|
|
725
753
|
export const getSecondaryDataWithOffsetIncluded = (
|
|
726
|
-
secondaryData?:
|
|
727
|
-
secondaryYAxis?: any,
|
|
754
|
+
secondaryData?: barDataItem[] | lineDataItem[],
|
|
755
|
+
secondaryYAxis?: any | undefined,
|
|
728
756
|
showDataPointsForMissingValues?: boolean,
|
|
729
757
|
interpolateMissingValues?: boolean,
|
|
730
758
|
onlyPositive?: boolean
|
|
731
|
-
) => {
|
|
732
|
-
if (!secondaryData) return secondaryData
|
|
759
|
+
): barDataItem[] | lineDataItem[] | undefined => {
|
|
760
|
+
if (!secondaryData) return secondaryData
|
|
733
761
|
const nullishHandledData = getInterpolatedData(
|
|
734
762
|
secondaryData,
|
|
735
763
|
showDataPointsForMissingValues,
|
|
736
764
|
interpolateMissingValues,
|
|
737
765
|
onlyPositive
|
|
738
|
-
)
|
|
766
|
+
)
|
|
739
767
|
if (secondaryYAxis?.yAxisOffset) {
|
|
740
768
|
return nullishHandledData.map((item) => {
|
|
741
|
-
item.value = item.value - (secondaryYAxis?.yAxisOffset ?? 0)
|
|
742
|
-
return item
|
|
743
|
-
})
|
|
769
|
+
item.value = item.value - (secondaryYAxis?.yAxisOffset ?? 0)
|
|
770
|
+
return item
|
|
771
|
+
})
|
|
744
772
|
}
|
|
745
|
-
return nullishHandledData
|
|
746
|
-
}
|
|
773
|
+
return nullishHandledData
|
|
774
|
+
}
|
|
747
775
|
|
|
748
776
|
export const getArrowProperty = (
|
|
749
777
|
property: string,
|
|
750
778
|
count: number,
|
|
751
|
-
props:
|
|
779
|
+
props: extendedLineChartPropsType,
|
|
752
780
|
defaultArrowConfig: arrowConfigType
|
|
753
|
-
) => {
|
|
781
|
+
): any => {
|
|
782
|
+
const arrowNumber = `arrowConfig${count}` as keyof extendedLineChartPropsType
|
|
754
783
|
return (
|
|
755
|
-
props[
|
|
756
|
-
props[
|
|
757
|
-
defaultArrowConfig[
|
|
758
|
-
)
|
|
759
|
-
}
|
|
784
|
+
props[arrowNumber]?.[property] ??
|
|
785
|
+
props['arrowConfig' as keyof extendedLineChartPropsType]?.[property] ??
|
|
786
|
+
defaultArrowConfig[property as keyof arrowConfigType]
|
|
787
|
+
)
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
interface IgetAllArrowProperties {
|
|
791
|
+
arrowLength1: number
|
|
792
|
+
arrowWidth1: number
|
|
793
|
+
arrowStrokeWidth1: number
|
|
794
|
+
arrowStrokeColor1: ColorValue
|
|
795
|
+
arrowFillColor1: ColorValue
|
|
796
|
+
showArrowBase1: boolean
|
|
797
|
+
arrowLength2: number
|
|
798
|
+
arrowWidth2: number
|
|
799
|
+
arrowStrokeWidth2: number
|
|
800
|
+
arrowStrokeColor2: ColorValue
|
|
801
|
+
arrowFillColor2: ColorValue
|
|
802
|
+
showArrowBase2: boolean
|
|
803
|
+
arrowLength3: number
|
|
804
|
+
arrowWidth3: number
|
|
805
|
+
arrowStrokeWidth3: number
|
|
806
|
+
arrowStrokeColor3: ColorValue
|
|
807
|
+
arrowFillColor3: ColorValue
|
|
808
|
+
showArrowBase3: boolean
|
|
809
|
+
arrowLength4: number
|
|
810
|
+
arrowWidth4: number
|
|
811
|
+
arrowStrokeWidth4: number
|
|
812
|
+
arrowStrokeColor4: ColorValue
|
|
813
|
+
arrowFillColor4: ColorValue
|
|
814
|
+
showArrowBase4: boolean
|
|
815
|
+
arrowLength5: number
|
|
816
|
+
arrowWidth5: number
|
|
817
|
+
arrowStrokeWidth5: number
|
|
818
|
+
arrowStrokeColor5: ColorValue
|
|
819
|
+
arrowFillColor5: ColorValue
|
|
820
|
+
showArrowBase5: boolean
|
|
821
|
+
arrowLengthsFromSet?: number[]
|
|
822
|
+
arrowWidthsFromSet?: number[]
|
|
823
|
+
arrowStrokeWidthsFromSet?: number[]
|
|
824
|
+
arrowStrokeColorsFromSet?: ColorValue[]
|
|
825
|
+
arrowFillColorsFromSet?: ColorValue[]
|
|
826
|
+
showArrowBasesFromSet?: boolean[]
|
|
827
|
+
}
|
|
760
828
|
|
|
761
829
|
export const getAllArrowProperties = (
|
|
762
|
-
props:
|
|
830
|
+
props: extendedLineChartPropsType,
|
|
763
831
|
defaultArrowConfig: arrowConfigType
|
|
764
|
-
) => {
|
|
765
|
-
const arrowLength1 = getArrowProperty(
|
|
766
|
-
const arrowWidth1 = getArrowProperty(
|
|
832
|
+
): IgetAllArrowProperties => {
|
|
833
|
+
const arrowLength1 = getArrowProperty('length', 1, props, defaultArrowConfig)
|
|
834
|
+
const arrowWidth1 = getArrowProperty('width', 1, props, defaultArrowConfig)
|
|
767
835
|
const arrowStrokeWidth1 = getArrowProperty(
|
|
768
|
-
|
|
836
|
+
'strokeWidth',
|
|
769
837
|
1,
|
|
770
838
|
props,
|
|
771
839
|
defaultArrowConfig
|
|
772
|
-
)
|
|
840
|
+
)
|
|
773
841
|
const arrowStrokeColor1 = getArrowProperty(
|
|
774
|
-
|
|
842
|
+
'strokeColor',
|
|
775
843
|
1,
|
|
776
844
|
props,
|
|
777
845
|
defaultArrowConfig
|
|
778
|
-
)
|
|
846
|
+
)
|
|
779
847
|
const arrowFillColor1 = getArrowProperty(
|
|
780
|
-
|
|
848
|
+
'fillColor',
|
|
781
849
|
1,
|
|
782
850
|
props,
|
|
783
851
|
defaultArrowConfig
|
|
784
|
-
)
|
|
852
|
+
)
|
|
785
853
|
const showArrowBase1 = getArrowProperty(
|
|
786
|
-
|
|
854
|
+
'showArrowBase',
|
|
787
855
|
1,
|
|
788
856
|
props,
|
|
789
857
|
defaultArrowConfig
|
|
790
|
-
)
|
|
858
|
+
)
|
|
791
859
|
|
|
792
|
-
const arrowLength2 = getArrowProperty(
|
|
793
|
-
const arrowWidth2 = getArrowProperty(
|
|
860
|
+
const arrowLength2 = getArrowProperty('length', 2, props, defaultArrowConfig)
|
|
861
|
+
const arrowWidth2 = getArrowProperty('width', 2, props, defaultArrowConfig)
|
|
794
862
|
const arrowStrokeWidth2 = getArrowProperty(
|
|
795
|
-
|
|
863
|
+
'strokeWidth',
|
|
796
864
|
2,
|
|
797
865
|
props,
|
|
798
866
|
defaultArrowConfig
|
|
799
|
-
)
|
|
867
|
+
)
|
|
800
868
|
const arrowStrokeColor2 = getArrowProperty(
|
|
801
|
-
|
|
869
|
+
'strokeColor',
|
|
802
870
|
2,
|
|
803
871
|
props,
|
|
804
872
|
defaultArrowConfig
|
|
805
|
-
)
|
|
873
|
+
)
|
|
806
874
|
const arrowFillColor2 = getArrowProperty(
|
|
807
|
-
|
|
875
|
+
'fillColor',
|
|
808
876
|
2,
|
|
809
877
|
props,
|
|
810
878
|
defaultArrowConfig
|
|
811
|
-
)
|
|
879
|
+
)
|
|
812
880
|
const showArrowBase2 = getArrowProperty(
|
|
813
|
-
|
|
881
|
+
'showArrowBase',
|
|
814
882
|
2,
|
|
815
883
|
props,
|
|
816
884
|
defaultArrowConfig
|
|
817
|
-
)
|
|
885
|
+
)
|
|
818
886
|
|
|
819
|
-
const arrowLength3 = getArrowProperty(
|
|
820
|
-
const arrowWidth3 = getArrowProperty(
|
|
887
|
+
const arrowLength3 = getArrowProperty('length', 3, props, defaultArrowConfig)
|
|
888
|
+
const arrowWidth3 = getArrowProperty('width', 3, props, defaultArrowConfig)
|
|
821
889
|
const arrowStrokeWidth3 = getArrowProperty(
|
|
822
|
-
|
|
890
|
+
'strokeWidth',
|
|
823
891
|
3,
|
|
824
892
|
props,
|
|
825
893
|
defaultArrowConfig
|
|
826
|
-
)
|
|
894
|
+
)
|
|
827
895
|
const arrowStrokeColor3 = getArrowProperty(
|
|
828
|
-
|
|
896
|
+
'strokeColor',
|
|
829
897
|
3,
|
|
830
898
|
props,
|
|
831
899
|
defaultArrowConfig
|
|
832
|
-
)
|
|
900
|
+
)
|
|
833
901
|
const arrowFillColor3 = getArrowProperty(
|
|
834
|
-
|
|
902
|
+
'fillColor',
|
|
835
903
|
3,
|
|
836
904
|
props,
|
|
837
905
|
defaultArrowConfig
|
|
838
|
-
)
|
|
906
|
+
)
|
|
839
907
|
const showArrowBase3 = getArrowProperty(
|
|
840
|
-
|
|
908
|
+
'showArrowBase',
|
|
841
909
|
3,
|
|
842
910
|
props,
|
|
843
911
|
defaultArrowConfig
|
|
844
|
-
)
|
|
912
|
+
)
|
|
845
913
|
|
|
846
|
-
const arrowLength4 = getArrowProperty(
|
|
847
|
-
const arrowWidth4 = getArrowProperty(
|
|
914
|
+
const arrowLength4 = getArrowProperty('length', 4, props, defaultArrowConfig)
|
|
915
|
+
const arrowWidth4 = getArrowProperty('width', 4, props, defaultArrowConfig)
|
|
848
916
|
const arrowStrokeWidth4 = getArrowProperty(
|
|
849
|
-
|
|
917
|
+
'strokeWidth',
|
|
850
918
|
4,
|
|
851
919
|
props,
|
|
852
920
|
defaultArrowConfig
|
|
853
|
-
)
|
|
921
|
+
)
|
|
854
922
|
const arrowStrokeColor4 = getArrowProperty(
|
|
855
|
-
|
|
923
|
+
'strokeColor',
|
|
856
924
|
4,
|
|
857
925
|
props,
|
|
858
926
|
defaultArrowConfig
|
|
859
|
-
)
|
|
927
|
+
)
|
|
860
928
|
const arrowFillColor4 = getArrowProperty(
|
|
861
|
-
|
|
929
|
+
'fillColor',
|
|
862
930
|
4,
|
|
863
931
|
props,
|
|
864
932
|
defaultArrowConfig
|
|
865
|
-
)
|
|
933
|
+
)
|
|
866
934
|
const showArrowBase4 = getArrowProperty(
|
|
867
|
-
|
|
935
|
+
'showArrowBase',
|
|
868
936
|
4,
|
|
869
937
|
props,
|
|
870
938
|
defaultArrowConfig
|
|
871
|
-
)
|
|
939
|
+
)
|
|
872
940
|
|
|
873
|
-
const arrowLength5 = getArrowProperty(
|
|
874
|
-
const arrowWidth5 = getArrowProperty(
|
|
941
|
+
const arrowLength5 = getArrowProperty('length', 5, props, defaultArrowConfig)
|
|
942
|
+
const arrowWidth5 = getArrowProperty('width', 5, props, defaultArrowConfig)
|
|
875
943
|
const arrowStrokeWidth5 = getArrowProperty(
|
|
876
|
-
|
|
944
|
+
'strokeWidth',
|
|
877
945
|
5,
|
|
878
946
|
props,
|
|
879
947
|
defaultArrowConfig
|
|
880
|
-
)
|
|
948
|
+
)
|
|
881
949
|
const arrowStrokeColor5 = getArrowProperty(
|
|
882
|
-
|
|
950
|
+
'strokeColor',
|
|
883
951
|
5,
|
|
884
952
|
props,
|
|
885
953
|
defaultArrowConfig
|
|
886
|
-
)
|
|
954
|
+
)
|
|
887
955
|
const arrowFillColor5 = getArrowProperty(
|
|
888
|
-
|
|
956
|
+
'fillColor',
|
|
889
957
|
5,
|
|
890
958
|
props,
|
|
891
959
|
defaultArrowConfig
|
|
892
|
-
)
|
|
960
|
+
)
|
|
893
961
|
const showArrowBase5 = getArrowProperty(
|
|
894
|
-
|
|
962
|
+
'showArrowBase',
|
|
895
963
|
5,
|
|
896
964
|
props,
|
|
897
965
|
defaultArrowConfig
|
|
898
|
-
)
|
|
966
|
+
)
|
|
899
967
|
|
|
900
968
|
const arrowLengthsFromSet = props.dataSet?.map(
|
|
901
969
|
(item) => item?.arrowConfig?.length ?? arrowLength1
|
|
902
|
-
)
|
|
970
|
+
)
|
|
903
971
|
const arrowWidthsFromSet = props.dataSet?.map(
|
|
904
|
-
(item) => item?.arrowConfig?.
|
|
905
|
-
)
|
|
972
|
+
(item) => item?.arrowConfig?.width ?? arrowWidth1
|
|
973
|
+
)
|
|
906
974
|
const arrowStrokeWidthsFromSet = props.dataSet?.map(
|
|
907
|
-
(item) => item?.arrowConfig?.
|
|
908
|
-
)
|
|
975
|
+
(item) => item?.arrowConfig?.strokeWidth ?? arrowStrokeWidth1
|
|
976
|
+
)
|
|
909
977
|
const arrowStrokeColorsFromSet = props.dataSet?.map(
|
|
910
|
-
(item) => item?.arrowConfig?.
|
|
911
|
-
)
|
|
978
|
+
(item) => item?.arrowConfig?.strokeColor ?? arrowStrokeColor1
|
|
979
|
+
)
|
|
912
980
|
const arrowFillColorsFromSet = props.dataSet?.map(
|
|
913
|
-
(item) => item?.arrowConfig?.
|
|
914
|
-
)
|
|
981
|
+
(item) => item?.arrowConfig?.fillColor ?? arrowFillColor1
|
|
982
|
+
)
|
|
915
983
|
const showArrowBasesFromSet = props.dataSet?.map(
|
|
916
984
|
(item) => item?.arrowConfig?.showArrowBase ?? showArrowBase1
|
|
917
|
-
)
|
|
985
|
+
)
|
|
918
986
|
|
|
919
987
|
return {
|
|
920
988
|
arrowLength1,
|
|
@@ -952,14 +1020,14 @@ export const getAllArrowProperties = (
|
|
|
952
1020
|
arrowStrokeWidthsFromSet,
|
|
953
1021
|
arrowStrokeColorsFromSet,
|
|
954
1022
|
arrowFillColorsFromSet,
|
|
955
|
-
showArrowBasesFromSet
|
|
956
|
-
}
|
|
957
|
-
}
|
|
1023
|
+
showArrowBasesFromSet
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
958
1026
|
|
|
959
|
-
|
|
960
|
-
maxItem: number
|
|
961
|
-
minItem: number
|
|
962
|
-
}
|
|
1027
|
+
interface MaxAndMin {
|
|
1028
|
+
maxItem: number
|
|
1029
|
+
minItem: number
|
|
1030
|
+
}
|
|
963
1031
|
|
|
964
1032
|
export const maxAndMinUtil = (
|
|
965
1033
|
maxItem: number,
|
|
@@ -967,81 +1035,78 @@ export const maxAndMinUtil = (
|
|
|
967
1035
|
roundToDigits?: number,
|
|
968
1036
|
showFractionalValues?: boolean
|
|
969
1037
|
): MaxAndMin => {
|
|
970
|
-
if (showFractionalValues
|
|
971
|
-
maxItem *= 10 * (roundToDigits
|
|
972
|
-
maxItem = maxItem + (10 - (maxItem % 10))
|
|
973
|
-
maxItem /= 10 * (roundToDigits
|
|
974
|
-
maxItem = parseFloat(maxItem.toFixed(roundToDigits
|
|
1038
|
+
if (showFractionalValues ?? roundToDigits) {
|
|
1039
|
+
maxItem *= 10 * (roundToDigits ?? 1)
|
|
1040
|
+
maxItem = maxItem + (10 - (maxItem % 10))
|
|
1041
|
+
maxItem /= 10 * (roundToDigits ?? 1)
|
|
1042
|
+
maxItem = parseFloat(maxItem.toFixed(roundToDigits ?? 1))
|
|
975
1043
|
|
|
976
1044
|
if (minItem !== 0) {
|
|
977
|
-
minItem *= 10 * (roundToDigits
|
|
978
|
-
minItem = minItem - (10 + (minItem % 10))
|
|
979
|
-
minItem /= 10 * (roundToDigits
|
|
980
|
-
minItem = parseFloat(minItem.toFixed(roundToDigits
|
|
1045
|
+
minItem *= 10 * (roundToDigits ?? 1)
|
|
1046
|
+
minItem = minItem - (10 + (minItem % 10))
|
|
1047
|
+
minItem /= 10 * (roundToDigits ?? 1)
|
|
1048
|
+
minItem = parseFloat(minItem.toFixed(roundToDigits ?? 1))
|
|
981
1049
|
}
|
|
982
1050
|
} else {
|
|
983
|
-
maxItem = maxItem + (10 - (maxItem % 10))
|
|
1051
|
+
maxItem = maxItem + (10 - (maxItem % 10))
|
|
984
1052
|
if (minItem !== 0) {
|
|
985
|
-
minItem = minItem - (10 + (minItem % 10))
|
|
1053
|
+
minItem = minItem - (10 + (minItem % 10))
|
|
986
1054
|
}
|
|
987
1055
|
}
|
|
988
1056
|
|
|
989
|
-
return { maxItem, minItem }
|
|
990
|
-
}
|
|
1057
|
+
return { maxItem, minItem }
|
|
1058
|
+
}
|
|
991
1059
|
|
|
992
1060
|
export const computeMaxAndMinItems = (
|
|
993
|
-
data: any,
|
|
1061
|
+
data: any[] | undefined,
|
|
994
1062
|
roundToDigits?: number,
|
|
995
1063
|
showFractionalValues?: boolean
|
|
996
1064
|
): MaxAndMin => {
|
|
997
1065
|
if (!data?.length) {
|
|
998
|
-
return { maxItem: 0, minItem: 0 }
|
|
1066
|
+
return { maxItem: 0, minItem: 0 }
|
|
999
1067
|
}
|
|
1000
|
-
let maxItem = 0
|
|
1001
|
-
|
|
1068
|
+
let maxItem = 0
|
|
1069
|
+
let minItem = 0
|
|
1002
1070
|
|
|
1003
1071
|
data.forEach((item: any) => {
|
|
1004
1072
|
if (item.value > maxItem) {
|
|
1005
|
-
maxItem = item.value
|
|
1073
|
+
maxItem = item.value
|
|
1006
1074
|
}
|
|
1007
1075
|
if (item.value < minItem) {
|
|
1008
|
-
minItem = item.value
|
|
1076
|
+
minItem = item.value
|
|
1009
1077
|
}
|
|
1010
|
-
})
|
|
1078
|
+
})
|
|
1011
1079
|
|
|
1012
|
-
return maxAndMinUtil(maxItem, minItem, roundToDigits, showFractionalValues)
|
|
1013
|
-
}
|
|
1080
|
+
return maxAndMinUtil(maxItem, minItem, roundToDigits, showFractionalValues)
|
|
1081
|
+
}
|
|
1014
1082
|
|
|
1015
1083
|
export const getLabelTextUtil = (
|
|
1016
|
-
val:
|
|
1084
|
+
val: string,
|
|
1017
1085
|
index: number,
|
|
1018
1086
|
showFractionalValues?: boolean,
|
|
1019
|
-
yAxisLabelTexts?:
|
|
1087
|
+
yAxisLabelTexts?: string[],
|
|
1020
1088
|
yAxisOffset?: number,
|
|
1021
1089
|
yAxisLabelPrefix?: string,
|
|
1022
1090
|
yAxisLabelSuffix?: string,
|
|
1023
1091
|
roundToDigits?: number,
|
|
1024
1092
|
formatYLabel?: (label: string) => string
|
|
1025
|
-
) => {
|
|
1026
|
-
let label =
|
|
1027
|
-
if (
|
|
1028
|
-
|
|
1029
|
-
(yAxisLabelTexts && yAxisLabelTexts[index] !== undefined)
|
|
1030
|
-
) {
|
|
1031
|
-
if (yAxisLabelTexts?.[index]) return val;
|
|
1093
|
+
): string => {
|
|
1094
|
+
let label = ''
|
|
1095
|
+
if (showFractionalValues ?? yAxisLabelTexts?.[index] !== undefined) {
|
|
1096
|
+
if (yAxisLabelTexts?.[index]) return val
|
|
1032
1097
|
if (val) {
|
|
1033
1098
|
label = isNaN(Number(val))
|
|
1034
1099
|
? val
|
|
1035
|
-
: (Number(val) + (yAxisOffset ?? 0)).toFixed(roundToDigits)
|
|
1100
|
+
: (Number(val) + (yAxisOffset ?? 0)).toFixed(roundToDigits)
|
|
1036
1101
|
} else {
|
|
1037
|
-
label = yAxisOffset?.toString() ??
|
|
1102
|
+
label = yAxisOffset?.toString() ?? '0'
|
|
1038
1103
|
}
|
|
1039
1104
|
} else {
|
|
1040
1105
|
if (val) {
|
|
1041
|
-
label = val.toString().split(
|
|
1042
|
-
label = (Number(label) + (yAxisOffset ?? 0)).toString()
|
|
1106
|
+
label = val.toString().split('.')[0]
|
|
1107
|
+
label = (Number(label) + (yAxisOffset ?? 0)).toString()
|
|
1043
1108
|
} else {
|
|
1044
|
-
label = yAxisOffset?.toString() ??
|
|
1109
|
+
label = yAxisOffset?.toString() ?? '0'
|
|
1045
1110
|
}
|
|
1046
1111
|
}
|
|
1047
1112
|
|
|
@@ -1049,8 +1114,8 @@ export const getLabelTextUtil = (
|
|
|
1049
1114
|
yAxisLabelPrefix +
|
|
1050
1115
|
(formatYLabel ? formatYLabel(label) : label) +
|
|
1051
1116
|
yAxisLabelSuffix
|
|
1052
|
-
)
|
|
1053
|
-
}
|
|
1117
|
+
)
|
|
1118
|
+
}
|
|
1054
1119
|
|
|
1055
1120
|
export const getXForLineInBar = (
|
|
1056
1121
|
index: number,
|
|
@@ -1059,75 +1124,84 @@ export const getXForLineInBar = (
|
|
|
1059
1124
|
yAxisLabelWidth: number,
|
|
1060
1125
|
lineConfig: any,
|
|
1061
1126
|
spacing: number
|
|
1062
|
-
) =>
|
|
1127
|
+
): number =>
|
|
1063
1128
|
yAxisLabelWidth +
|
|
1064
1129
|
firstBarWidth / 2 +
|
|
1065
1130
|
lineConfig.initialSpacing +
|
|
1066
1131
|
(currentBarWidth + (lineConfig.spacing ?? spacing)) * index +
|
|
1067
1132
|
lineConfig.shiftX -
|
|
1068
1133
|
lineConfig.dataPointsWidth / 2 -
|
|
1069
|
-
4
|
|
1134
|
+
4
|
|
1070
1135
|
|
|
1071
|
-
export const getYForLineInBar = (
|
|
1072
|
-
|
|
1136
|
+
export const getYForLineInBar = (
|
|
1137
|
+
value: number | undefined,
|
|
1138
|
+
shiftY: number | undefined,
|
|
1139
|
+
containerHeight: number,
|
|
1140
|
+
maxValue: number
|
|
1141
|
+
): number =>
|
|
1142
|
+
containerHeight - (shiftY ?? 0) - ((value ?? 0) * containerHeight) / maxValue
|
|
1073
1143
|
|
|
1074
|
-
export const clone = (obj) => {
|
|
1075
|
-
if (obj === null || typeof obj !==
|
|
1076
|
-
return obj
|
|
1144
|
+
export const clone = (obj: any): any => {
|
|
1145
|
+
if (obj === null || typeof obj !== 'object' || 'isActiveClone' in obj) {
|
|
1146
|
+
return obj
|
|
1147
|
+
}
|
|
1077
1148
|
|
|
1078
|
-
let temp
|
|
1079
|
-
if (obj instanceof Date) temp = new Date(obj)
|
|
1080
|
-
else temp = obj.constructor()
|
|
1149
|
+
let temp
|
|
1150
|
+
if (obj instanceof Date) temp = new Date(obj)
|
|
1151
|
+
else temp = obj.constructor()
|
|
1081
1152
|
|
|
1082
|
-
for (
|
|
1153
|
+
for (const key in obj) {
|
|
1083
1154
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1084
|
-
obj
|
|
1085
|
-
temp[key] = clone(obj[key])
|
|
1086
|
-
delete obj
|
|
1155
|
+
obj.isActiveClone = null
|
|
1156
|
+
temp[key] = clone(obj[key])
|
|
1157
|
+
delete obj.isActiveClone
|
|
1087
1158
|
}
|
|
1088
1159
|
}
|
|
1089
|
-
return temp
|
|
1090
|
-
}
|
|
1160
|
+
return temp
|
|
1161
|
+
}
|
|
1091
1162
|
|
|
1092
|
-
export const getLineConfigForBarChart = (
|
|
1163
|
+
export const getLineConfigForBarChart = (
|
|
1164
|
+
lineConfig: lineConfigType,
|
|
1165
|
+
barInitialSpacing: number
|
|
1166
|
+
): lineConfigType => {
|
|
1093
1167
|
return {
|
|
1094
1168
|
initialSpacing:
|
|
1095
1169
|
lineConfig.initialSpacing ??
|
|
1096
1170
|
barInitialSpacing ??
|
|
1097
1171
|
defaultLineConfig.initialSpacing,
|
|
1098
1172
|
spacing: lineConfig.spacing,
|
|
1099
|
-
curved: lineConfig.curved
|
|
1173
|
+
curved: lineConfig.curved ?? defaultLineConfig.curved,
|
|
1100
1174
|
curvature: lineConfig.curvature ?? defaultLineConfig.curvature,
|
|
1101
1175
|
curveType: lineConfig.curveType ?? defaultLineConfig.curveType,
|
|
1102
|
-
isAnimated: lineConfig.isAnimated
|
|
1176
|
+
isAnimated: lineConfig.isAnimated ?? defaultLineConfig.isAnimated,
|
|
1103
1177
|
animationDuration:
|
|
1104
|
-
lineConfig.animationDuration
|
|
1105
|
-
thickness: lineConfig.thickness
|
|
1106
|
-
color: lineConfig.color
|
|
1178
|
+
lineConfig.animationDuration ?? defaultLineConfig.animationDuration,
|
|
1179
|
+
thickness: lineConfig.thickness ?? defaultLineConfig.thickness,
|
|
1180
|
+
color: lineConfig.color ?? defaultLineConfig.color,
|
|
1107
1181
|
hideDataPoints:
|
|
1108
|
-
lineConfig.hideDataPoints
|
|
1182
|
+
lineConfig.hideDataPoints ?? defaultLineConfig.hideDataPoints,
|
|
1109
1183
|
dataPointsShape:
|
|
1110
|
-
lineConfig.dataPointsShape
|
|
1184
|
+
lineConfig.dataPointsShape ?? defaultLineConfig.dataPointsShape,
|
|
1111
1185
|
dataPointsHeight:
|
|
1112
|
-
lineConfig.dataPointsHeight
|
|
1186
|
+
lineConfig.dataPointsHeight ?? defaultLineConfig.dataPointsHeight,
|
|
1113
1187
|
dataPointsWidth:
|
|
1114
|
-
lineConfig.dataPointsWidth
|
|
1188
|
+
lineConfig.dataPointsWidth ?? defaultLineConfig.dataPointsWidth,
|
|
1115
1189
|
dataPointsColor:
|
|
1116
|
-
lineConfig.dataPointsColor
|
|
1190
|
+
lineConfig.dataPointsColor ?? defaultLineConfig.dataPointsColor,
|
|
1117
1191
|
dataPointsRadius:
|
|
1118
|
-
lineConfig.dataPointsRadius
|
|
1119
|
-
textColor: lineConfig.textColor
|
|
1120
|
-
textFontSize: lineConfig.textFontSize
|
|
1121
|
-
textShiftX: lineConfig.textShiftX
|
|
1122
|
-
textShiftY: lineConfig.textShiftY
|
|
1123
|
-
shiftX: lineConfig.shiftX
|
|
1124
|
-
shiftY: lineConfig.shiftY
|
|
1125
|
-
delay: lineConfig.delay
|
|
1126
|
-
startIndex: lineConfig.startIndex
|
|
1192
|
+
lineConfig.dataPointsRadius ?? defaultLineConfig.dataPointsRadius,
|
|
1193
|
+
textColor: lineConfig.textColor ?? defaultLineConfig.textColor,
|
|
1194
|
+
textFontSize: lineConfig.textFontSize ?? defaultLineConfig.textFontSize,
|
|
1195
|
+
textShiftX: lineConfig.textShiftX ?? defaultLineConfig.textShiftX,
|
|
1196
|
+
textShiftY: lineConfig.textShiftY ?? defaultLineConfig.textShiftY,
|
|
1197
|
+
shiftX: lineConfig.shiftX ?? defaultLineConfig.shiftX,
|
|
1198
|
+
shiftY: lineConfig.shiftY ?? defaultLineConfig.shiftY,
|
|
1199
|
+
delay: lineConfig.delay ?? defaultLineConfig.delay,
|
|
1200
|
+
startIndex: lineConfig.startIndex ?? defaultLineConfig.startIndex,
|
|
1127
1201
|
endIndex:
|
|
1128
1202
|
lineConfig.endIndex === 0
|
|
1129
1203
|
? 0
|
|
1130
|
-
: lineConfig.endIndex
|
|
1204
|
+
: lineConfig.endIndex ?? defaultLineConfig.endIndex,
|
|
1131
1205
|
|
|
1132
1206
|
showArrow: lineConfig.showArrow ?? defaultLineConfig.showArrow,
|
|
1133
1207
|
arrowConfig: {
|
|
@@ -1150,79 +1224,87 @@ export const getLineConfigForBarChart = (lineConfig, barInitialSpacing) => {
|
|
|
1150
1224
|
|
|
1151
1225
|
showArrowBase:
|
|
1152
1226
|
lineConfig.arrowConfig?.showArrowBase ??
|
|
1153
|
-
defaultLineConfig.arrowConfig?.showArrowBase
|
|
1227
|
+
defaultLineConfig.arrowConfig?.showArrowBase
|
|
1154
1228
|
},
|
|
1155
1229
|
customDataPoint: lineConfig.customDataPoint,
|
|
1156
|
-
isSecondary: lineConfig.isSecondary ?? defaultLineConfig.isSecondary
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1230
|
+
isSecondary: lineConfig.isSecondary ?? defaultLineConfig.isSecondary
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1159
1233
|
|
|
1160
|
-
export const getNoOfSections = (
|
|
1234
|
+
export const getNoOfSections = (
|
|
1235
|
+
noOfSections: number | undefined,
|
|
1236
|
+
maxValue: number | undefined,
|
|
1237
|
+
stepValue: number | undefined
|
|
1238
|
+
): number =>
|
|
1161
1239
|
maxValue && stepValue
|
|
1162
1240
|
? maxValue / stepValue
|
|
1163
|
-
: noOfSections ?? AxesAndRulesDefaults.noOfSections
|
|
1241
|
+
: noOfSections ?? AxesAndRulesDefaults.noOfSections
|
|
1164
1242
|
|
|
1165
|
-
export const getMaxValue = (
|
|
1166
|
-
maxValue
|
|
1243
|
+
export const getMaxValue = (
|
|
1244
|
+
maxValue: number | undefined,
|
|
1245
|
+
stepValue: number | undefined,
|
|
1246
|
+
noOfSections: number,
|
|
1247
|
+
maxItem: number
|
|
1248
|
+
): number => maxValue ?? (stepValue ? stepValue * noOfSections : maxItem)
|
|
1167
1249
|
|
|
1168
1250
|
export const getBarFrontColor = (
|
|
1169
|
-
isFocused,
|
|
1170
|
-
focusedBarConfig,
|
|
1171
|
-
itemFrontColor,
|
|
1172
|
-
frontColor,
|
|
1173
|
-
isThreeD
|
|
1174
|
-
) => {
|
|
1251
|
+
isFocused?: boolean,
|
|
1252
|
+
focusedBarConfig?: FocusedBarConfig,
|
|
1253
|
+
itemFrontColor?: ColorValue,
|
|
1254
|
+
frontColor?: ColorValue,
|
|
1255
|
+
isThreeD?: boolean
|
|
1256
|
+
): ColorValue => {
|
|
1175
1257
|
if (isFocused) {
|
|
1176
1258
|
return (
|
|
1177
1259
|
focusedBarConfig?.color ??
|
|
1178
1260
|
(isThreeD
|
|
1179
1261
|
? BarDefaults.focusedThreeDBarFrontColor
|
|
1180
1262
|
: BarDefaults.focusedBarFrontColor)
|
|
1181
|
-
)
|
|
1263
|
+
)
|
|
1182
1264
|
}
|
|
1183
1265
|
return (
|
|
1184
|
-
itemFrontColor
|
|
1185
|
-
frontColor
|
|
1266
|
+
itemFrontColor ??
|
|
1267
|
+
frontColor ??
|
|
1186
1268
|
(isThreeD ? BarDefaults.threeDBarFrontColor : BarDefaults.frontColor)
|
|
1187
|
-
)
|
|
1188
|
-
}
|
|
1269
|
+
)
|
|
1270
|
+
}
|
|
1189
1271
|
|
|
1190
1272
|
export const getBarSideColor = (
|
|
1191
|
-
isFocused,
|
|
1192
|
-
focusedBarConfig,
|
|
1193
|
-
itemSideColor,
|
|
1194
|
-
sideColor
|
|
1195
|
-
) => {
|
|
1273
|
+
isFocused?: boolean,
|
|
1274
|
+
focusedBarConfig?: FocusedBarConfig,
|
|
1275
|
+
itemSideColor?: ColorValue,
|
|
1276
|
+
sideColor?: ColorValue
|
|
1277
|
+
): ColorValue | undefined => {
|
|
1196
1278
|
if (isFocused) {
|
|
1197
|
-
return focusedBarConfig?.sideColor ?? BarDefaults.focusedBarSideColor
|
|
1279
|
+
return focusedBarConfig?.sideColor ?? BarDefaults.focusedBarSideColor
|
|
1198
1280
|
}
|
|
1199
|
-
return itemSideColor
|
|
1200
|
-
}
|
|
1281
|
+
return itemSideColor ?? sideColor
|
|
1282
|
+
}
|
|
1201
1283
|
|
|
1202
1284
|
export const getBarTopColor = (
|
|
1203
|
-
isFocused,
|
|
1204
|
-
focusedBarConfig,
|
|
1205
|
-
itemTopColor,
|
|
1206
|
-
topColor
|
|
1207
|
-
) => {
|
|
1285
|
+
isFocused?: boolean,
|
|
1286
|
+
focusedBarConfig?: FocusedBarConfig,
|
|
1287
|
+
itemTopColor?: ColorValue,
|
|
1288
|
+
topColor?: ColorValue
|
|
1289
|
+
): ColorValue | undefined => {
|
|
1208
1290
|
if (isFocused) {
|
|
1209
|
-
return focusedBarConfig?.topColor ?? BarDefaults.focusedBarTopColor
|
|
1291
|
+
return focusedBarConfig?.topColor ?? BarDefaults.focusedBarTopColor
|
|
1210
1292
|
}
|
|
1211
|
-
return itemTopColor
|
|
1212
|
-
}
|
|
1293
|
+
return itemTopColor ?? topColor
|
|
1294
|
+
}
|
|
1213
1295
|
|
|
1214
1296
|
export const getBarWidth = (
|
|
1215
|
-
isFocused,
|
|
1216
|
-
focusedBarConfig,
|
|
1217
|
-
itemBarWidth,
|
|
1218
|
-
barWidth
|
|
1219
|
-
) => {
|
|
1220
|
-
const localBarWidth = itemBarWidth
|
|
1297
|
+
isFocused?: boolean,
|
|
1298
|
+
focusedBarConfig?: FocusedBarConfig,
|
|
1299
|
+
itemBarWidth?: number,
|
|
1300
|
+
barWidth?: number
|
|
1301
|
+
): number => {
|
|
1302
|
+
const localBarWidth = itemBarWidth ?? barWidth ?? BarDefaults.barWidth
|
|
1221
1303
|
if (isFocused) {
|
|
1222
|
-
return focusedBarConfig?.width ?? localBarWidth
|
|
1304
|
+
return focusedBarConfig?.width ?? localBarWidth
|
|
1223
1305
|
}
|
|
1224
|
-
return localBarWidth
|
|
1225
|
-
}
|
|
1306
|
+
return localBarWidth
|
|
1307
|
+
}
|
|
1226
1308
|
|
|
1227
1309
|
export const getInterpolatedData = (
|
|
1228
1310
|
dataParam: lineDataItem[],
|
|
@@ -1232,43 +1314,43 @@ export const getInterpolatedData = (
|
|
|
1232
1314
|
): lineDataItem[] => {
|
|
1233
1315
|
if (!interpolateMissingValues) {
|
|
1234
1316
|
return dataParam.map((item) => {
|
|
1235
|
-
if (typeof item.value !==
|
|
1236
|
-
if (showDataPointsForMissingValues) return { ...item, value: 0 }
|
|
1237
|
-
return { ...item, value: 0, hideDataPoint: true }
|
|
1317
|
+
if (typeof item.value !== 'number') {
|
|
1318
|
+
if (showDataPointsForMissingValues) return { ...item, value: 0 }
|
|
1319
|
+
return { ...item, value: 0, hideDataPoint: true }
|
|
1238
1320
|
}
|
|
1239
|
-
return item
|
|
1240
|
-
})
|
|
1321
|
+
return item
|
|
1322
|
+
})
|
|
1241
1323
|
}
|
|
1242
|
-
if (!interpolateMissingValues) return dataParam
|
|
1243
|
-
const data = clone(dataParam)
|
|
1244
|
-
const n = data.length
|
|
1324
|
+
if (!interpolateMissingValues) return dataParam
|
|
1325
|
+
const data: lineDataItem[] = clone(dataParam)
|
|
1326
|
+
const n = data.length
|
|
1245
1327
|
|
|
1246
|
-
|
|
1247
|
-
let numericValue
|
|
1328
|
+
/** ************ PRE-PROCESSING **************/
|
|
1329
|
+
let numericValue: number
|
|
1248
1330
|
const numericValuesLength = data.filter((item) => {
|
|
1249
|
-
const isNum = typeof item.value ===
|
|
1331
|
+
const isNum = typeof item.value === 'number'
|
|
1250
1332
|
if (isNum) {
|
|
1251
|
-
numericValue = item.value
|
|
1252
|
-
return true
|
|
1333
|
+
numericValue = item.value
|
|
1334
|
+
return true
|
|
1253
1335
|
}
|
|
1254
|
-
return false
|
|
1255
|
-
}).length
|
|
1336
|
+
return false
|
|
1337
|
+
}).length
|
|
1256
1338
|
|
|
1257
|
-
if (!numericValuesLength) return []
|
|
1339
|
+
if (!numericValuesLength) return []
|
|
1258
1340
|
|
|
1259
1341
|
if (numericValuesLength === 1) {
|
|
1260
1342
|
data.forEach((item) => {
|
|
1261
|
-
if (!showDataPointsForMissingValues && typeof item.value !==
|
|
1262
|
-
item.hideDataPoint = true
|
|
1343
|
+
if (!showDataPointsForMissingValues && typeof item.value !== 'number') {
|
|
1344
|
+
item.hideDataPoint = true
|
|
1263
1345
|
}
|
|
1264
|
-
item.value = numericValue
|
|
1265
|
-
})
|
|
1266
|
-
return data
|
|
1346
|
+
item.value = numericValue
|
|
1347
|
+
})
|
|
1348
|
+
return data
|
|
1267
1349
|
}
|
|
1268
1350
|
/**********************************************************************/
|
|
1269
1351
|
|
|
1270
1352
|
data.forEach((item, index) => {
|
|
1271
|
-
if (typeof item.value ===
|
|
1353
|
+
if (typeof item.value === 'number') return
|
|
1272
1354
|
// Cut the line in 2 halves-> pre and post
|
|
1273
1355
|
// Now there are 4 possibilities-
|
|
1274
1356
|
// 1. Both pre and post have valid values
|
|
@@ -1276,133 +1358,135 @@ export const getInterpolatedData = (
|
|
|
1276
1358
|
// 3. Only post has valid value
|
|
1277
1359
|
// 4. None has valid value -> this is already handled in preprocessing
|
|
1278
1360
|
|
|
1279
|
-
const pre = data.slice(0, index)
|
|
1280
|
-
const post = data.slice(index + 1, n)
|
|
1361
|
+
const pre: lineDataItem[] = data.slice(0, index)
|
|
1362
|
+
const post: lineDataItem[] = data.slice(index + 1, n)
|
|
1281
1363
|
|
|
1282
1364
|
const preValidIndex = pre.findLastIndex(
|
|
1283
|
-
(item) => typeof item.value ===
|
|
1284
|
-
)
|
|
1365
|
+
(item) => typeof item.value === 'number'
|
|
1366
|
+
)
|
|
1285
1367
|
const postValidInd = post.findIndex(
|
|
1286
|
-
(item) => typeof item.value ===
|
|
1287
|
-
)
|
|
1288
|
-
const postValidIndex = postValidInd + index + 1
|
|
1368
|
+
(item) => typeof item.value === 'number'
|
|
1369
|
+
)
|
|
1370
|
+
const postValidIndex = postValidInd + index + 1
|
|
1289
1371
|
|
|
1290
|
-
let count, step
|
|
1372
|
+
let count, step
|
|
1291
1373
|
|
|
1292
1374
|
// 1. Both pre and post have valid values
|
|
1293
1375
|
if (preValidIndex !== -1 && postValidInd !== -1) {
|
|
1294
|
-
count = postValidIndex - preValidIndex
|
|
1295
|
-
step = (data[postValidIndex].value - data[preValidIndex].value) / count
|
|
1376
|
+
count = postValidIndex - preValidIndex
|
|
1377
|
+
step = (data[postValidIndex].value - data[preValidIndex].value) / count
|
|
1296
1378
|
data[index].value =
|
|
1297
|
-
data[preValidIndex].value + step * (index - preValidIndex)
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
// 2. Only pre has valid value
|
|
1301
|
-
else if (preValidIndex !== -1 && postValidInd === -1) {
|
|
1379
|
+
data[preValidIndex].value + step * (index - preValidIndex)
|
|
1380
|
+
} else if (preValidIndex !== -1 && postValidInd === -1) {
|
|
1381
|
+
// 2. Only pre has valid value
|
|
1302
1382
|
// Now there are 2 possibilities-
|
|
1303
1383
|
// 1. There's only 1 valid value in the pre -> this is already handled in preprocessing
|
|
1304
1384
|
// 2. There are more than valid values in pre
|
|
1305
|
-
const secondPre = data.slice(0, preValidIndex)
|
|
1385
|
+
const secondPre: lineDataItem[] = data.slice(0, preValidIndex)
|
|
1306
1386
|
const secondPreIndex = secondPre.findLastIndex(
|
|
1307
|
-
(item) => typeof item.value ===
|
|
1308
|
-
)
|
|
1387
|
+
(item) => typeof item.value === 'number'
|
|
1388
|
+
)
|
|
1309
1389
|
|
|
1310
|
-
count = preValidIndex - secondPreIndex
|
|
1311
|
-
step = (data[secondPreIndex].value - data[preValidIndex].value) / count
|
|
1390
|
+
count = preValidIndex - secondPreIndex
|
|
1391
|
+
step = (data[secondPreIndex].value - data[preValidIndex].value) / count
|
|
1312
1392
|
data[index].value =
|
|
1313
|
-
data[preValidIndex].value - step * (index - preValidIndex)
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
// 3. Only post has valid value
|
|
1317
|
-
else if (preValidIndex === -1 && postValidInd !== -1) {
|
|
1393
|
+
data[preValidIndex].value - step * (index - preValidIndex)
|
|
1394
|
+
} else if (preValidIndex === -1 && postValidInd !== -1) {
|
|
1395
|
+
// 3. Only post has valid value
|
|
1318
1396
|
// Now there are 2 possibilities-
|
|
1319
1397
|
// 1. There's only 1 valid value in the post -> this is already handled in preprocessing
|
|
1320
1398
|
// 2. There are more than valid values in post
|
|
1321
1399
|
|
|
1322
|
-
const secondPost = data.slice(postValidIndex + 1, n)
|
|
1400
|
+
const secondPost: lineDataItem[] = data.slice(postValidIndex + 1, n)
|
|
1323
1401
|
const secondPostInd = secondPost.findIndex(
|
|
1324
|
-
(item) => typeof item.value ===
|
|
1325
|
-
)
|
|
1326
|
-
const secondPostIndex = secondPostInd + postValidIndex + 1
|
|
1402
|
+
(item) => typeof item.value === 'number'
|
|
1403
|
+
)
|
|
1404
|
+
const secondPostIndex = secondPostInd + postValidIndex + 1
|
|
1327
1405
|
|
|
1328
|
-
count = secondPostIndex - postValidIndex
|
|
1329
|
-
step = (data[secondPostIndex].value - data[postValidIndex].value) / count
|
|
1406
|
+
count = secondPostIndex - postValidIndex
|
|
1407
|
+
step = (data[secondPostIndex].value - data[postValidIndex].value) / count
|
|
1330
1408
|
data[index].value =
|
|
1331
|
-
data[postValidIndex].value - step * (postValidIndex - index)
|
|
1409
|
+
data[postValidIndex].value - step * (postValidIndex - index)
|
|
1332
1410
|
}
|
|
1333
1411
|
|
|
1334
1412
|
// hide data point (since it is interpolated)
|
|
1335
1413
|
if (!showDataPointsForMissingValues) {
|
|
1336
|
-
item.hideDataPoint = true
|
|
1414
|
+
item.hideDataPoint = true
|
|
1337
1415
|
}
|
|
1338
|
-
})
|
|
1416
|
+
})
|
|
1339
1417
|
return onlyPositive
|
|
1340
1418
|
? data.map((item) => ({ ...item, value: Math.max(item.value, 0) }))
|
|
1341
|
-
: data
|
|
1342
|
-
}
|
|
1419
|
+
: data
|
|
1420
|
+
}
|
|
1343
1421
|
|
|
1344
1422
|
export const getLineSegmentsForMissingValues = (
|
|
1345
1423
|
data?: lineDataItem[]
|
|
1346
1424
|
): LineSegment[] | undefined => {
|
|
1347
|
-
if (!data?.length) return undefined
|
|
1348
|
-
let i
|
|
1349
|
-
|
|
1425
|
+
if (!data?.length) return undefined
|
|
1426
|
+
let i
|
|
1427
|
+
const n = data.length
|
|
1350
1428
|
const numericValuesLength = data.filter(
|
|
1351
|
-
(item) => typeof item.value ===
|
|
1352
|
-
).length
|
|
1353
|
-
if (!numericValuesLength) return undefined
|
|
1354
|
-
const segments: LineSegment[] = []
|
|
1429
|
+
(item) => typeof item.value === 'number'
|
|
1430
|
+
).length
|
|
1431
|
+
if (!numericValuesLength) return undefined
|
|
1432
|
+
const segments: LineSegment[] = []
|
|
1355
1433
|
for (i = 0; i < n; i++) {
|
|
1356
|
-
if (typeof data[i].value !==
|
|
1357
|
-
const nextValidInd = data
|
|
1434
|
+
if (typeof data[i].value !== 'number') {
|
|
1435
|
+
const nextValidInd: number = data
|
|
1358
1436
|
.slice(i + 1, n)
|
|
1359
|
-
.findIndex((item) => typeof item.value ===
|
|
1437
|
+
.findIndex((item) => typeof item.value === 'number')
|
|
1360
1438
|
if (nextValidInd === -1) {
|
|
1361
1439
|
segments.push({
|
|
1362
1440
|
startIndex: Math.max(i - 1, 0),
|
|
1363
1441
|
endIndex: n,
|
|
1364
|
-
color:
|
|
1365
|
-
})
|
|
1366
|
-
break
|
|
1442
|
+
color: 'transparent'
|
|
1443
|
+
})
|
|
1444
|
+
break
|
|
1367
1445
|
}
|
|
1368
|
-
const nextValidIndex = nextValidInd + i + 1
|
|
1446
|
+
const nextValidIndex: number = nextValidInd + i + 1
|
|
1369
1447
|
segments.push({
|
|
1370
1448
|
startIndex: Math.max(i - 1, 0),
|
|
1371
1449
|
endIndex: nextValidIndex,
|
|
1372
|
-
color:
|
|
1373
|
-
})
|
|
1374
|
-
i = nextValidIndex
|
|
1450
|
+
color: 'transparent'
|
|
1451
|
+
})
|
|
1452
|
+
i = nextValidIndex
|
|
1375
1453
|
}
|
|
1376
1454
|
}
|
|
1377
|
-
return segments
|
|
1378
|
-
}
|
|
1455
|
+
return segments
|
|
1456
|
+
}
|
|
1379
1457
|
|
|
1380
1458
|
export const getTextSizeForPieLabels = (
|
|
1381
1459
|
textSize: number,
|
|
1382
1460
|
radius: number
|
|
1383
|
-
): number => (textSize ? Math.min(textSize, radius / 5) : 16)
|
|
1461
|
+
): number => (textSize ? Math.min(textSize, radius / 5) : 16)
|
|
1384
1462
|
|
|
1385
|
-
export const adjustToOffset = (
|
|
1386
|
-
data
|
|
1463
|
+
export const adjustToOffset = (
|
|
1464
|
+
data: lineDataItem[],
|
|
1465
|
+
yAxisOffset?: number
|
|
1466
|
+
): lineDataItem[] =>
|
|
1467
|
+
data.map((item) => ({ ...item, value: item.value - (yAxisOffset ?? 0) }))
|
|
1387
1468
|
|
|
1388
|
-
export const getSanitisedData = (
|
|
1469
|
+
export const getSanitisedData = (
|
|
1470
|
+
data: lineDataItem[] | undefined,
|
|
1471
|
+
dataSanitisationProps: IDataSanitisationProps
|
|
1472
|
+
): lineDataItem[] => {
|
|
1389
1473
|
if (!data) {
|
|
1390
|
-
return []
|
|
1474
|
+
return []
|
|
1391
1475
|
}
|
|
1392
1476
|
const {
|
|
1393
1477
|
showDataPointsForMissingValues,
|
|
1394
1478
|
interpolateMissingValues,
|
|
1395
1479
|
onlyPositive,
|
|
1396
|
-
yAxisOffset
|
|
1397
|
-
} = dataSanitisationProps
|
|
1480
|
+
yAxisOffset
|
|
1481
|
+
} = dataSanitisationProps
|
|
1398
1482
|
const nullishHandledData = getInterpolatedData(
|
|
1399
1483
|
data,
|
|
1400
1484
|
showDataPointsForMissingValues,
|
|
1401
1485
|
interpolateMissingValues,
|
|
1402
1486
|
onlyPositive
|
|
1403
|
-
)
|
|
1487
|
+
)
|
|
1404
1488
|
if (yAxisOffset) {
|
|
1405
|
-
return adjustToOffset(nullishHandledData, yAxisOffset)
|
|
1489
|
+
return adjustToOffset(nullishHandledData, yAxisOffset)
|
|
1406
1490
|
}
|
|
1407
|
-
return nullishHandledData
|
|
1408
|
-
}
|
|
1491
|
+
return nullishHandledData
|
|
1492
|
+
}
|