jpemberthy / ezgraphix

[NOT MAINTAINED] A rails plugin to generate flash based graphics using a free and customizable chart's set.
http://ezgraphixdemo.heroku.com/
28 stars 5 forks source link

Color should not be rendered randomly #1

Open rosenfeld opened 14 years ago

rosenfeld commented 14 years ago

The current implementation allows duplicate colors in the series data, making it impossible to figure out what bar is related to which legend, for instance.

Additionally, it would be good if the colors were consistent among the charts, so the user could be more comfortable reading the graphs.

I would suggest replacing rand_color for something like:

 def initialize
    # ...
    @current_color = -1
 end
 def next_color
    @current_color = (@current_color + 1) % Graphic::COLORS.size
    COLORS[@current_color]
  end
jpemberthy commented 14 years ago

Definetely there are some problems using random colors. Your suggestion from a point of view is valid, and could be improved to support an initial color, or initial random color, that way we could customize at least the first color, in order to avoid always the same initialization for all our graphics if desired.

Also, we should be able to pass a collection of colors to the graphic. e.g:

@graphic.colors = [:red, :white, :blue]

If no colors are present, then we should be able to use either rand_colors or next_color passing them as options to the constructor:

@graphic = Graphic.new(:colors_mode => :rand)
@graphic = Graphic.new(:corors_mode => :next)

We can create a new branch and start working on it!

rosenfeld commented 14 years ago

Additionally, it should be possible to define the default colors_mode and colors array globally:

Graphic.default_colors_mode = :next
Graphic.default_colors_sequence = [:red, :yellow, :blue]

I guess this result could be achieved in an hour, but I'm really in a hurry the last days due to series of coincidences (I work as freelancer at night and my main work is demanding me all my time these days due to lots of recent request from various clients - and I was asked a week ago to prepare a presentation about Rails at the main IT department of the college where I have graduated some time ago).

That said, I could probably send you a patch or fork your project and create a branch, but not so soon. Maybe after 2 weeks. For now I just monkey patched your plugin for using the :next mode at my freelancer system.

Best regards and thank you for your work on this plugin!

jpemberthy commented 14 years ago

Sure, I'm in a similar situation (a lot of work these days), but as You said It shouldn't take us too much time, so, I'll create a new branch for these colors settings as soon as I get some time!.

Best regards! and thanks!

rosenfeld commented 14 years ago

I've sent you a first pull request regarding this issue...

jpemberthy commented 14 years ago

Applied. Thanks!