@@ -13,23 +13,14 @@ import {
13
13
} from '../../const' ;
14
14
import {
15
15
clearCanvas ,
16
- createSvgBlobUrl ,
17
16
drawLinearLayerBackground ,
18
17
drawRoundedRect ,
19
18
drawSeparatorLinearLayer ,
20
19
drawSvgImageWithColor ,
21
- loadSvgImage ,
22
20
maxPositionValue ,
23
21
positionOnGraphScale ,
24
22
} from '../../utils' ;
25
23
26
- const questionSvg =
27
- '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13M6.92 6.085h.001a.75.75 0 1 1-1.342-.67c.169-.339.436-.701.849-.977C6.845 4.16 7.369 4 8 4a2.76 2.76 0 0 1 1.637.525c.503.377.863.965.863 1.725 0 .448-.115.83-.329 1.15-.205.307-.47.513-.692.662-.109.072-.22.138-.313.195l-.006.004a6 6 0 0 0-.26.16 1 1 0 0 0-.276.245.75.75 0 0 1-1.248-.832c.184-.264.42-.489.692-.661q.154-.1.313-.195l.007-.004c.1-.061.182-.11.258-.161a1 1 0 0 0 .277-.245C8.96 6.514 9 6.427 9 6.25a.61.61 0 0 0-.262-.525A1.27 1.27 0 0 0 8 5.5c-.369 0-.595.09-.74.187-.146.1-.263.238-.34.398M9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/></svg>' ;
28
- const alertFillSvg =
29
- '<svg xmlns="http://www.w3.org/2000/svg" width = "16" height = "16" viewBox = "0 0 16 16" > <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575zM8 5a.75.75 0 0 0-.75.75v2.5a.75.75 0 0 0 1.5 0v-2.5A.75.75 0 0 0 8 5m1 6a1 1 0 1 0-2 0 1 1 0 0 0 2 0" /> </svg>' ;
30
- const questionBlobUrl = createSvgBlobUrl ( questionSvg ) ;
31
- const alertFillBlobUrl = createSvgBlobUrl ( alertFillSvg ) ;
32
-
33
24
const RECT_HEIGHT = 17 ;
34
25
const Y_POSITION = 12 ;
35
26
const RECTANGLE_SPACING = 1 ;
@@ -43,11 +34,12 @@ const TEXT_PADDING_TOP = 1;
43
34
const ICON_BACKGROUND_WIDTH = 24 ;
44
35
const ICON_BACKGROUND_HEIGHT = 24 ;
45
36
46
- export const drawSpeedLimitTags = async ( {
37
+ export const drawSpeedLimitTags = ( {
47
38
ctx,
48
39
width,
49
40
height : marginTop ,
50
41
store,
42
+ images,
51
43
} : SpeedLimitTagsLayerDrawFunctionParams ) => {
52
44
const {
53
45
speedLimitTags,
@@ -65,9 +57,6 @@ export const drawSpeedLimitTags = async ({
65
57
66
58
const maxPosition = maxPositionValue ( store . speeds ) ;
67
59
68
- const questionImage = await loadSvgImage ( questionBlobUrl ) ;
69
- const alertFillImage = await loadSvgImage ( alertFillBlobUrl ) ;
70
-
71
60
let speedLimitTagsBackgroundColor = LINEAR_LAYERS_BACKGROUND_COLOR . FIRST ;
72
61
73
62
if ( electricalProfiles && powerRestrictions ) {
@@ -127,7 +116,7 @@ export const drawSpeedLimitTags = async ({
127
116
}
128
117
129
118
if ( tag === 'incompatible' || tag === 'missing_from_train' ) {
130
- const image = tag === 'incompatible' ? alertFillImage : questionImage ;
119
+ const image = tag === 'incompatible' ? images . alertFillImage : images . questionImage ;
131
120
132
121
ctx . fillStyle = color ;
133
122
@@ -143,16 +132,16 @@ export const drawSpeedLimitTags = async ({
143
132
ICON_BACKGROUND_HEIGHT ,
144
133
cornerRadius
145
134
) ;
146
-
147
- drawSvgImageWithColor (
148
- ctx ,
149
- image ,
150
- iconXPosition + ICON_OFFSET ,
151
- iconYPosition + ICON_OFFSET ,
152
- ICON_WIDTH ,
153
- ICON_HEIGHT ,
154
- WHITE . hex ( )
155
- ) ;
135
+ if ( image !== null )
136
+ drawSvgImageWithColor (
137
+ ctx ,
138
+ image ,
139
+ iconXPosition + ICON_OFFSET ,
140
+ iconYPosition + ICON_OFFSET ,
141
+ ICON_WIDTH ,
142
+ ICON_HEIGHT ,
143
+ WHITE . hex ( )
144
+ ) ;
156
145
} else {
157
146
ctx . fillStyle = 'white' ;
158
147
ctx . font = '600 12px "IBM Plex Sans"' ;
@@ -172,11 +161,11 @@ export const drawSpeedLimitTags = async ({
172
161
ctx . clearRect ( width - MARGIN_RIGHT , 0 , width , LINEAR_LAYERS_HEIGHTS . SPEED_LIMIT_TAGS_HEIGHT ) ;
173
162
} ;
174
163
175
- export const computeTooltip = async ( {
164
+ export const computeTooltip = ( {
176
165
width,
177
166
height : marginTop ,
178
167
store,
179
- } : DrawFunctionParams ) : Promise < tooltipInfos | null > => {
168
+ } : DrawFunctionParams ) : tooltipInfos | null => {
180
169
const { speedLimitTags, ratioX, leftOffset, cursor } = store ;
181
170
182
171
const { MARGIN_TOP , MARGIN_LEFT } = MARGINS ;
0 commit comments