@@ -22,6 +22,21 @@ let UNIT_COORDS = {};
22
22
// Map of unit index to the index it was unlocked by.
23
23
let REVERSE_UNIT_DEPS = { } ;
24
24
let REVERSE_UNIT_RMETA_DEPS = { } ;
25
+
26
+ // Colors from css
27
+ const getCssColor = name => getComputedStyle ( document . body ) . getPropertyValue ( name ) ;
28
+ const TEXT_COLOR = getCssColor ( '--text' ) ;
29
+ const BG_COLOR = getCssColor ( '--background' ) ;
30
+ const CANVAS_BG = getCssColor ( '--canvas-background' ) ;
31
+ const AXES_COLOR = getCssColor ( '--canvas-axes' ) ;
32
+ const GRID_COLOR = getCssColor ( '--canvas-grid' ) ;
33
+ const BLOCK_COLOR = getCssColor ( '--canvas-block' ) ;
34
+ const CUSTOM_BUILD_COLOR = getCssColor ( '--canvas-custom-build' ) ;
35
+ const NOT_CUSTOM_BUILD_COLOR = getCssColor ( '--canvas-not-custom-build' ) ;
36
+ const DEP_LINE_COLOR = getCssColor ( '--canvas-dep-line' ) ;
37
+ const DEP_LINE_HIGHLIGHTED_COLOR = getCssColor ( '--canvas-dep-line-highlighted' ) ;
38
+ const CPU_COLOR = getCssColor ( '--canvas-cpu' ) ;
39
+
25
40
for ( let n = 0 ; n < UNIT_DATA . length ; n ++ ) {
26
41
let unit = UNIT_DATA [ n ] ;
27
42
for ( let unlocked of unit . unlocked_units ) {
@@ -52,7 +67,7 @@ function render_pipeline_graph() {
52
67
// Canvas for hover highlights. This is a separate layer to improve performance.
53
68
const linectx = setup_canvas ( 'pipeline-graph-lines' , canvas_width , canvas_height ) ;
54
69
linectx . clearRect ( 0 , 0 , canvas_width , canvas_height ) ;
55
-
70
+ ctx . strokeStyle = AXES_COLOR ;
56
71
// Draw Y tick marks.
57
72
for ( let n = 1 ; n < units . length ; n ++ ) {
58
73
const y = MARGIN + Y_TICK_DIST * n ;
@@ -65,6 +80,7 @@ function render_pipeline_graph() {
65
80
// Draw Y labels.
66
81
ctx . textAlign = 'end' ;
67
82
ctx . textBaseline = 'middle' ;
83
+ ctx . fillStyle = AXES_COLOR ;
68
84
for ( let n = 0 ; n < units . length ; n ++ ) {
69
85
let y = MARGIN + Y_TICK_DIST * n + Y_TICK_DIST / 2 ;
70
86
ctx . fillText ( n + 1 , X_LINE - 4 , y ) ;
@@ -101,18 +117,18 @@ function render_pipeline_graph() {
101
117
HIT_BOXES . push ( { x : X_LINE + x , y :MARGIN + y , x2 : X_LINE + x + width , y2 : MARGIN + y + BOX_HEIGHT , i : unit . i } ) ;
102
118
103
119
ctx . beginPath ( ) ;
104
- ctx . fillStyle = unit . mode == 'run-custom-build' ? '#f0b165' : '#95cce8' ;
120
+ ctx . fillStyle = unit . mode == 'run-custom-build' ? CUSTOM_BUILD_COLOR : NOT_CUSTOM_BUILD_COLOR ;
105
121
roundedRect ( ctx , x , y , width , BOX_HEIGHT , RADIUS ) ;
106
122
ctx . fill ( ) ;
107
123
108
124
if ( unit . rmeta_time != null ) {
109
125
ctx . beginPath ( ) ;
110
- ctx . fillStyle = '#aa95e8' ;
126
+ ctx . fillStyle = BLOCK_COLOR ;
111
127
let ctime = unit . duration - unit . rmeta_time ;
112
128
roundedRect ( ctx , rmeta_x , y , px_per_sec * ctime , BOX_HEIGHT , RADIUS ) ;
113
129
ctx . fill ( ) ;
114
130
}
115
- ctx . fillStyle = "#000" ;
131
+ ctx . fillStyle = TEXT_COLOR ;
116
132
ctx . textAlign = 'start' ;
117
133
ctx . textBaseline = 'middle' ;
118
134
ctx . font = '14px sans-serif' ;
@@ -145,7 +161,7 @@ function draw_dep_lines(ctx, unit_idx, highlighted) {
145
161
function draw_one_dep_line ( ctx , from_x , from_y , to_unit , highlighted ) {
146
162
if ( to_unit in UNIT_COORDS ) {
147
163
let { x : u_x , y : u_y } = UNIT_COORDS [ to_unit ] ;
148
- ctx . strokeStyle = highlighted ? '#000' : '#ddd' ;
164
+ ctx . strokeStyle = highlighted ? DEP_LINE_HIGHLIGHTED_COLOR : DEP_LINE_COLOR ;
149
165
ctx . setLineDash ( [ 2 ] ) ;
150
166
ctx . beginPath ( ) ;
151
167
ctx . moveTo ( from_x , from_y + BOX_HEIGHT / 2 ) ;
@@ -204,7 +220,7 @@ function render_timing_graph() {
204
220
} ;
205
221
}
206
222
207
- const cpuFillStyle = 'rgba(250, 119, 0, 0.2)' ;
223
+ const cpuFillStyle = CPU_COLOR ;
208
224
if ( CPU_USAGE . length > 1 ) {
209
225
ctx . beginPath ( ) ;
210
226
ctx . fillStyle = cpuFillStyle ;
@@ -245,8 +261,8 @@ function render_timing_graph() {
245
261
ctx . save ( ) ;
246
262
ctx . translate ( canvas_width - 200 , MARGIN ) ;
247
263
// background
248
- ctx . fillStyle = '#fff' ;
249
- ctx . strokeStyle = '#000' ;
264
+ ctx . fillStyle = BG_COLOR ;
265
+ ctx . strokeStyle = TEXT_COLOR ;
250
266
ctx . lineWidth = 1 ;
251
267
ctx . textBaseline = 'middle'
252
268
ctx . textAlign = 'start' ;
@@ -255,7 +271,7 @@ function render_timing_graph() {
255
271
ctx . stroke ( ) ;
256
272
ctx . fill ( ) ;
257
273
258
- ctx . fillStyle = '#000'
274
+ ctx . fillStyle = TEXT_COLOR ;
259
275
ctx . beginPath ( ) ;
260
276
ctx . lineWidth = 2 ;
261
277
ctx . strokeStyle = 'red' ;
@@ -282,7 +298,7 @@ function render_timing_graph() {
282
298
ctx . fillStyle = cpuFillStyle
283
299
ctx . fillRect ( 15 , 60 , 30 , 15 ) ;
284
300
ctx . fill ( ) ;
285
- ctx . fillStyle = 'black' ;
301
+ ctx . fillStyle = TEXT_COLOR ;
286
302
ctx . fillText ( 'CPU Usage' , 54 , 71 ) ;
287
303
288
304
ctx . restore ( ) ;
@@ -311,12 +327,13 @@ function draw_graph_axes(id, graph_height) {
311
327
const canvas_width = Math . max ( graph_width + X_LINE + 30 , X_LINE + 250 ) ;
312
328
const canvas_height = graph_height + MARGIN + Y_LINE ;
313
329
let ctx = setup_canvas ( id , canvas_width , canvas_height ) ;
314
- ctx . fillStyle = '#f7f7f7' ;
330
+ ctx . fillStyle = CANVAS_BG ;
315
331
ctx . fillRect ( 0 , 0 , canvas_width , canvas_height ) ;
316
332
317
333
ctx . lineWidth = 2 ;
318
334
ctx . font = '16px sans-serif' ;
319
335
ctx . textAlign = 'center' ;
336
+ ctx . strokeStyle = AXES_COLOR ;
320
337
321
338
// Draw main axes.
322
339
ctx . beginPath ( ) ;
@@ -327,7 +344,7 @@ function draw_graph_axes(id, graph_height) {
327
344
328
345
// Draw X tick marks.
329
346
const { step, tick_dist, num_ticks} = split_ticks ( DURATION , px_per_sec , graph_width ) ;
330
- ctx . fillStyle = '#303030' ;
347
+ ctx . fillStyle = AXES_COLOR ;
331
348
for ( let n = 0 ; n < num_ticks ; n ++ ) {
332
349
const x = X_LINE + ( ( n + 1 ) * tick_dist ) ;
333
350
ctx . beginPath ( ) ;
@@ -339,7 +356,7 @@ function draw_graph_axes(id, graph_height) {
339
356
}
340
357
341
358
// Draw vertical lines.
342
- ctx . strokeStyle = '#e6e6e6' ;
359
+ ctx . strokeStyle = GRID_COLOR ;
343
360
ctx . setLineDash ( [ 2 , 4 ] ) ;
344
361
for ( n = 0 ; n < num_ticks ; n ++ ) {
345
362
const x = X_LINE + ( ( n + 1 ) * tick_dist ) ;
@@ -348,7 +365,7 @@ function draw_graph_axes(id, graph_height) {
348
365
ctx . lineTo ( x , MARGIN + graph_height ) ;
349
366
ctx . stroke ( ) ;
350
367
}
351
- ctx . strokeStyle = '#000' ;
368
+ ctx . strokeStyle = TEXT_COLOR ;
352
369
ctx . setLineDash ( [ ] ) ;
353
370
return { canvas_width, canvas_height, graph_width, graph_height, ctx, px_per_sec} ;
354
371
}
0 commit comments