Permalink
Browse files

[enhance] WChart: allowing simple color config for charts.

  • Loading branch information...
1 parent e413a8d commit a61804b90c950b0548976ac5552f3540b910de62 @akoprow akoprow committed Oct 11, 2011
Showing with 18 additions and 6 deletions.
  1. +6 −1 stdlib/widgets/chart/bar.opa
  2. +5 −4 stdlib/widgets/chart/chart.opa
  3. +7 −1 stdlib/widgets/chart/line.opa
@@ -22,14 +22,18 @@
type WBarChart.config = {
+ bg_style : Canvas.style
+ bar_fill_style : Canvas.style
margins : WChart.percentage
bar_spacing : WChart.percentage
}
WBarChart = {{
default_config : WBarChart.config =
- { margins = 0.1
+ { bg_style = {color = Color.black}
+ ; bar_fill_style = {color = Color.black}
+ ; margins = 0.1
; bar_spacing = 0.1
}
@@ -52,6 +56,7 @@ WBarChart = {{
y2 = hf * (1. - config.margins)
px = Int.of_float
Canvas.fill_rect(canvas, px(x1), px(y2 - ys), px(x2 - x1), px(y2))
+ do Canvas.set_fill_style(canvas, config.bar_fill_style)
do List.iteri(generate_bar, data.data)
{success}
@@ -29,10 +29,10 @@ type WChart.config = {
}
@abstract
-type WChart.chart =
- { config : WChart.config
- ; id : string
- }
+type WChart.chart = {
+ config : WChart.config
+ id : string
+}
type WChart.failure = {canvas_not_found}
/ {canvas_2d_context_not_found}
@@ -57,6 +57,7 @@ WChart = {{
| {some=ctx} ->
w = Dom.get_width(canvas_dom)
h = Dom.get_height(canvas_dom)
+ do Canvas.set_fill_style(ctx, config.bg_style)
do Canvas.clear_rect(ctx, 0, 0, w, h)
draw_on(config, data, ctx, w, h)
@@ -22,13 +22,18 @@
type WLineChart.config = {
+ bg_style : Canvas.style
+ line_stroke_style : Canvas.style
margin_px : int
}
WLineChart = {{
default_config : WLineChart.config =
- { margin_px = 3 }
+ { line_stroke_style = {color = Color.black}
+ ; bg_style = {color = Color.black}
+ ; margin_px = 3
+ }
// @private
draw(config, data, canvas, w, h) =
@@ -45,6 +50,7 @@ WLineChart = {{
posx(i) = fl(i) |> fx |> px
posy(v) = h - (fy(v) |> px)
draw(i, v) = Canvas.line_to(canvas, posx(i + 1), posy(v))
+ do Canvas.set_stroke_style(canvas, config.line_stroke_style)
do Canvas.begin_path(canvas)
do match data.data with
| [] -> void

0 comments on commit a61804b

Please sign in to comment.