Changeset 5070

Show
Ignore:
Timestamp:
12/11/07 22:48:34 (6 years ago)
Author:
khali
Message:

sensord: Use the same colors for daily and weekly charts.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5069 r5070  
    1010             Warn about outputs found in automatic mode 
    1111  sensord: Fix rrd support (#2276) 
     12           Use the same colors for daily and weekly charts 
    1213  sensors-detect: Drop PCA9540 detection 
    1314 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/rrd.c

    r5069 r5070  
    295295} 
    296296 
     297/* Compute an arbitrary color based on the sensor label. This is preferred 
     298   over a random value because this guarantees that daily and weekly charts 
     299   will use the same colors. */ 
     300static int 
     301rrdCGI_color 
     302(const char *label) { 
     303  unsigned long color = 0, brightness; 
     304  const char *c; 
     305 
     306  for (c = label; *c; c++) { 
     307    color = (color << 6) + (color >> (*c & 7)); 
     308    color ^= (*c) * 0x401; 
     309  } 
     310  color &= 0xffffff; 
     311  /* Adjust very light colors */ 
     312  brightness = (color & 0xff) + ((color >> 8) & 0xff) + (color >> 16); 
     313  if (brightness > 672) 
     314    color &= 0x7f7f7f; 
     315  /* Adjust very dark colors */ 
     316  else if (brightness < 96) 
     317    color |= 0x808080; 
     318  return color; 
     319} 
     320 
    297321static int 
    298322rrdCGI_LINE 
     
    300324  struct gr *data = (struct gr *) _data; 
    301325  if (!feature || (feature->rrd && (feature->type == data->type))) 
    302     printf ("\n\tLINE2:%s#%.6x:\"%s\"", rawLabel, (int) random () & 0xffffff, label); 
     326    printf ("\n\tLINE2:%s#%.6x:\"%s\"", rawLabel, rrdCGI_color(label), label); 
    303327  return 0; 
    304328}