@@ -22,6 +22,21 @@ let UNIT_COORDS = {};
2222// Map of unit index to the index it was unlocked by. 
2323let  REVERSE_UNIT_DEPS  =  { } ; 
2424let  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+ 
2540for  ( let  n = 0 ;  n < UNIT_DATA . length ;  n ++ )  { 
2641  let  unit  =  UNIT_DATA [ n ] ; 
2742  for  ( let  unlocked  of  unit . unlocked_units )  { 
@@ -52,7 +67,7 @@ function render_pipeline_graph() {
5267  // Canvas for hover highlights. This is a separate layer to improve performance. 
5368  const  linectx  =  setup_canvas ( 'pipeline-graph-lines' ,  canvas_width ,  canvas_height ) ; 
5469  linectx . clearRect ( 0 ,  0 ,  canvas_width ,  canvas_height ) ; 
55- 
70+    ctx . strokeStyle   =   AXES_COLOR ; 
5671  // Draw Y tick marks. 
5772  for  ( let  n = 1 ;  n < units . length ;  n ++ )  { 
5873    const  y  =  MARGIN  +  Y_TICK_DIST  *  n ; 
@@ -65,6 +80,7 @@ function render_pipeline_graph() {
6580  // Draw Y labels. 
6681  ctx . textAlign  =  'end' ; 
6782  ctx . textBaseline  =  'middle' ; 
83+   ctx . fillStyle  =  AXES_COLOR ; 
6884  for  ( let  n = 0 ;  n < units . length ;  n ++ )  { 
6985    let  y  =  MARGIN  +  Y_TICK_DIST  *  n  +  Y_TICK_DIST  /  2 ; 
7086    ctx . fillText ( n + 1 ,  X_LINE - 4 ,  y ) ; 
@@ -101,18 +117,18 @@ function render_pipeline_graph() {
101117    HIT_BOXES . push ( { x : X_LINE + x ,  y :MARGIN + y ,  x2 : X_LINE + x + width ,  y2 : MARGIN + y + BOX_HEIGHT ,  i : unit . i } ) ; 
102118
103119    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 ; 
105121    roundedRect ( ctx ,  x ,  y ,  width ,  BOX_HEIGHT ,  RADIUS ) ; 
106122    ctx . fill ( ) ; 
107123
108124    if  ( unit . rmeta_time  !=  null )  { 
109125      ctx . beginPath ( ) ; 
110-       ctx . fillStyle  =  '#aa95e8' ; 
126+       ctx . fillStyle  =  BLOCK_COLOR ; 
111127      let  ctime  =  unit . duration  -  unit . rmeta_time ; 
112128      roundedRect ( ctx ,  rmeta_x ,  y ,  px_per_sec  *  ctime ,  BOX_HEIGHT ,  RADIUS ) ; 
113129      ctx . fill ( ) ; 
114130    } 
115-     ctx . fillStyle  =  "#000" ; 
131+     ctx . fillStyle  =  TEXT_COLOR ; 
116132    ctx . textAlign  =  'start' ; 
117133    ctx . textBaseline  =  'middle' ; 
118134    ctx . font  =  '14px sans-serif' ; 
@@ -145,7 +161,7 @@ function draw_dep_lines(ctx, unit_idx, highlighted) {
145161function  draw_one_dep_line ( ctx ,  from_x ,  from_y ,  to_unit ,  highlighted )  { 
146162  if  ( to_unit  in  UNIT_COORDS )  { 
147163    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 ; 
149165    ctx . setLineDash ( [ 2 ] ) ; 
150166    ctx . beginPath ( ) ; 
151167    ctx . moveTo ( from_x ,  from_y + BOX_HEIGHT / 2 ) ; 
@@ -204,7 +220,7 @@ function render_timing_graph() {
204220    } ; 
205221  } 
206222
207-   const  cpuFillStyle  =  'rgba(250, 119, 0, 0.2)' ; 
223+   const  cpuFillStyle  =  CPU_COLOR ; 
208224  if  ( CPU_USAGE . length  >  1 )  { 
209225    ctx . beginPath ( ) ; 
210226    ctx . fillStyle  =  cpuFillStyle ; 
@@ -245,8 +261,8 @@ function render_timing_graph() {
245261  ctx . save ( ) ; 
246262  ctx . translate ( canvas_width - 200 ,  MARGIN ) ; 
247263  // background 
248-   ctx . fillStyle  =  '#fff' ; 
249-   ctx . strokeStyle  =  '#000' ; 
264+   ctx . fillStyle  =  BG_COLOR ; 
265+   ctx . strokeStyle  =  TEXT_COLOR ; 
250266  ctx . lineWidth  =  1 ; 
251267  ctx . textBaseline  =  'middle' 
252268  ctx . textAlign  =  'start' ; 
@@ -255,7 +271,7 @@ function render_timing_graph() {
255271  ctx . stroke ( ) ; 
256272  ctx . fill ( ) ; 
257273
258-   ctx . fillStyle  =  '#000' 
274+   ctx . fillStyle  =  TEXT_COLOR ; 
259275  ctx . beginPath ( ) ; 
260276  ctx . lineWidth  =  2 ; 
261277  ctx . strokeStyle  =  'red' ; 
@@ -282,7 +298,7 @@ function render_timing_graph() {
282298  ctx . fillStyle  =  cpuFillStyle 
283299  ctx . fillRect ( 15 ,  60 ,  30 ,  15 ) ; 
284300  ctx . fill ( ) ; 
285-   ctx . fillStyle  =  'black' ; 
301+   ctx . fillStyle  =  TEXT_COLOR ; 
286302  ctx . fillText ( 'CPU Usage' ,  54 ,  71 ) ; 
287303
288304  ctx . restore ( ) ; 
@@ -311,12 +327,13 @@ function draw_graph_axes(id, graph_height) {
311327  const  canvas_width  =  Math . max ( graph_width  +  X_LINE  +  30 ,  X_LINE  +  250 ) ; 
312328  const  canvas_height  =  graph_height  +  MARGIN  +  Y_LINE ; 
313329  let  ctx  =  setup_canvas ( id ,  canvas_width ,  canvas_height ) ; 
314-   ctx . fillStyle  =  '#f7f7f7' ; 
330+   ctx . fillStyle  =  CANVAS_BG ; 
315331  ctx . fillRect ( 0 ,  0 ,  canvas_width ,  canvas_height ) ; 
316332
317333  ctx . lineWidth  =  2 ; 
318334  ctx . font  =  '16px sans-serif' ; 
319335  ctx . textAlign  =  'center' ; 
336+   ctx . strokeStyle  =  AXES_COLOR ; 
320337
321338  // Draw main axes. 
322339  ctx . beginPath ( ) ; 
@@ -327,7 +344,7 @@ function draw_graph_axes(id, graph_height) {
327344
328345  // Draw X tick marks. 
329346  const  { step,  tick_dist,  num_ticks}  =  split_ticks ( DURATION ,  px_per_sec ,  graph_width ) ; 
330-   ctx . fillStyle  =  '#303030' ; 
347+   ctx . fillStyle  =  AXES_COLOR ; 
331348  for  ( let  n = 0 ;  n < num_ticks ;  n ++ )  { 
332349    const  x  =  X_LINE  +  ( ( n  +  1 )  *  tick_dist ) ; 
333350    ctx . beginPath ( ) ; 
@@ -339,7 +356,7 @@ function draw_graph_axes(id, graph_height) {
339356  } 
340357
341358  // Draw vertical lines. 
342-   ctx . strokeStyle  =  '#e6e6e6' ; 
359+   ctx . strokeStyle  =  GRID_COLOR ; 
343360  ctx . setLineDash ( [ 2 ,  4 ] ) ; 
344361  for  ( n = 0 ;  n < num_ticks ;  n ++ )  { 
345362    const  x  =  X_LINE  +  ( ( n  +  1 )  *  tick_dist ) ; 
@@ -348,7 +365,7 @@ function draw_graph_axes(id, graph_height) {
348365    ctx . lineTo ( x ,  MARGIN + graph_height ) ; 
349366    ctx . stroke ( ) ; 
350367  } 
351-   ctx . strokeStyle  =  '#000' ; 
368+   ctx . strokeStyle  =  TEXT_COLOR ; 
352369  ctx . setLineDash ( [ ] ) ; 
353370  return  { canvas_width,  canvas_height,  graph_width,  graph_height,  ctx,  px_per_sec} ; 
354371} 
0 commit comments