Pergunta

I've got an app that's basically a calendar, the users can enter events for each day. Now I have to find the best way to show the calendar for a full month while highlighting the busiest days.

Obviously the color is the choice here, but I'm wondering how you guys would do it. I have brainstormed the following:

  • Get the max events for a day and from there, divide it by the number of colors available. So if one day had 30 events and we have 3 colors, the first one would be from 0 to 9, the following from 10 to 19 and the last from 20 on.
  • Find the average and divide it by colors/2, so if the average is 10 events and we have 3 colors, the math would be 10/1.5 = 6.66 which means that the first color range will be from 0 to 6.66, the second from 6.67 to 13.32 and the last from 13.33 on.

However, I'm not sure this would be the best way to solve this. Both are linear and the first could mess the things quite a bit if our average is about 20 and the maximum had 100 events, just two colors will be showing up.

I'm no statician, but I think this problem could be solved with percentiles and quartiles, but I'm not really sure how to implement it.

Thanks.

Foi útil?

Solução

I would suggest an algorithm for a logarthmic distribution which is often used for building tag clouds. Tags are your days, counts of tags are the number of events for a day.

A good implementation for PHP and Python (not checked it properly yet) seems to be this one. Here's an example:

$tags = array(
    array('tag'   => 1,
          'count' => 10),
    array('tag'   => 2,
          'count' => 30),
    array('tag'   => 3,
          'count' => 5),
    array('tag'   => 4,
          'count' => 5));
$colours = array('green', 'yellow', 'red');
foreach(tagcloud($tags, 0, count($colours) - 1, 0) as $d) {
  echo  '<div style="background-color:' . $colours[floor($d['size'])] . '">Day: '.$d['tag'].' Events: '.$d['count'].'</div>';
}

Outras dicas

A few ideas:

  1. Ensure an even distribution of colors: Order the N events/day and assign an equal number of days to each color
  2. Map the N events/day to a value in a continuous color range instead of using discrete buckets. For example, 0 to max(events) to an RGB value.
  3. Find a non-linear distribution - e.g., normal, exponential, etc. The formula you're looking for is the CDF (see http://en.wikipedia.org/wiki/Cumulative_distribution_function) which can be used to convert the number of events/day to a percentile.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top