@@ -5,7 +5,7 @@ import type {
5
5
LayerData ,
6
6
} from '../../../types/chartTypes' ;
7
7
import { MARGINS } from '../../const' ;
8
- import { clearCanvas , maxPositionValue , speedRangeValues } from '../../utils' ;
8
+ import { clearCanvas , maxPositionValue , maxSpeedValue } from '../../utils' ;
9
9
10
10
const { CURVE_MARGIN_TOP , CURVE_MARGIN_SIDES } = MARGINS ;
11
11
@@ -14,7 +14,7 @@ const drawSpecificCurve = (
14
14
canvasConfig : CanvasConfig ,
15
15
specificSpeeds : LayerData < number > [ ]
16
16
) => {
17
- const { minSpeed , speedRange , maxPosition, ratioX } = curveConfig ;
17
+ const { maxSpeed , maxPosition, ratioX } = curveConfig ;
18
18
const { width, height, ctx } = canvasConfig ;
19
19
20
20
const adjustedWidth = width - CURVE_MARGIN_SIDES ;
@@ -24,7 +24,7 @@ const drawSpecificCurve = (
24
24
25
25
return specificSpeeds . forEach ( ( { position, value } ) => {
26
26
// normalize speed based on range of values
27
- const normalizedSpeed = ( value - minSpeed ) / speedRange ;
27
+ const normalizedSpeed = value / maxSpeed ;
28
28
const x = position . start * xcoef + halfCurveMarginSides ;
29
29
const y = height - normalizedSpeed * adjustedHeight ;
30
30
ctx . lineTo ( x , y ) ;
@@ -39,15 +39,15 @@ export const drawCurve = ({ ctx, width, height, store }: DrawFunctionParams) =>
39
39
ctx . save ( ) ;
40
40
ctx . translate ( leftOffset , 0 ) ;
41
41
42
- const { minSpeed , speedRange } = speedRangeValues ( store ) ;
42
+ const maxSpeed = maxSpeedValue ( store ) ;
43
43
const maxPosition = maxPositionValue ( store ) ;
44
44
45
45
ctx . lineWidth = 0.5 ;
46
46
ctx . fillStyle = 'rgba(17, 101, 180, 0.02)' ;
47
47
ctx . strokeStyle = 'rgb(17, 101, 180, 0.5)' ;
48
48
49
49
ctx . beginPath ( ) ;
50
- drawSpecificCurve ( { minSpeed , speedRange , maxPosition, ratioX } , { width, height, ctx } , speeds ) ;
50
+ drawSpecificCurve ( { maxSpeed , maxPosition, ratioX } , { width, height, ctx } , speeds ) ;
51
51
ctx . closePath ( ) ;
52
52
ctx . fill ( ) ;
53
53
@@ -58,11 +58,7 @@ export const drawCurve = ({ ctx, width, height, store }: DrawFunctionParams) =>
58
58
ctx . globalCompositeOperation = 'destination-out' ;
59
59
60
60
ctx . beginPath ( ) ;
61
- drawSpecificCurve (
62
- { minSpeed, speedRange, maxPosition, ratioX } ,
63
- { width, height, ctx } ,
64
- ecoSpeeds
65
- ) ;
61
+ drawSpecificCurve ( { maxSpeed, maxPosition, ratioX } , { width, height, ctx } , ecoSpeeds ) ;
66
62
ctx . closePath ( ) ;
67
63
ctx . fill ( ) ;
68
64
ctx . globalCompositeOperation = 'source-over' ;
0 commit comments