Skip to content

Commit

Permalink
camelCase -> snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
monstasat committed Aug 14, 2019
1 parent 2cadeff commit e902990
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 296 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
## Plugins

* [ ] Crosshair
* [ ] Datalabels
* [ ] Streaming
* [X] Datalabels
* [X] Streaming
* [ ] Deferred
1 change: 1 addition & 0 deletions chartjs-datalabels.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ depends: [
"dune" {build}
"js_of_ocaml"
"js_of_ocaml-ppx"
"chartjs"
]
1 change: 1 addition & 0 deletions chartjs-streaming.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ depends: [
"dune" {build}
"js_of_ocaml"
"js_of_ocaml-ppx"
"chartjs"
]
48 changes: 24 additions & 24 deletions examples/bar/bar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@ open Chartjs
let log x : unit = Js.Unsafe.global##.console##log x

let () =
let dataset1 =
createBarDataset
@@ Js.array [|10.; 15.; 30.; 20.; 25.; 10.; 7.|] in
(* Create first dataset. *)
let dataset1 = create_bar_dataset () in
dataset1##.data := Js.array [|10.; 15.; 30.; 20.; 25.; 10.; 7.|];
dataset1##.label := Js.string "Dataset 1";
dataset1##.borderColor := Scriptable_indexable.of_single @@ Color.of_string "red";
dataset1##.backgroundColor := (
Scriptable_indexable.of_single
@@ Color.of_string "rgba(255, 0, 0, 0.4)");
dataset1##.label := Js.string "Dataset 1";
let dataset2 =
createBarDataset
@@ Js.array [|20.; 10.; nan; 15.; 5.; 7.; 30.|] in
(* Create second dataset. *)
let dataset2 = create_bar_dataset () in
dataset2##.data := Js.array [|20.; 10.; nan; 15.; 5.; 7.; 30.|];
dataset2##.label := Js.string "Dataset 2";
dataset2##.borderColor := Scriptable_indexable.of_single @@ Color.of_string "blue";
dataset2##.backgroundColor := (
Scriptable_indexable.of_single
@@ Color.of_string "rgba(0, 0, 255, 0.4)");
dataset2##.label := Js.string "Dataset 2";
(* Create chart data. *)
let labels =
List.map Js.string
[ "January"
; "February"
; "March"
; "April"
; "May"
; "June"
; "July"
] in
let data = createData
~datasets:[dataset1; dataset2]
~labels
() in
Array.map Js.string
[| "January"
; "February"
; "March"
; "April"
; "May"
; "June"
; "July"
|] in
let data = create_data () in
data##.datasets := Js.array [|dataset1; dataset2|];
data##.labels := Js.array labels;
(* Initialize title *)
let title = createTitle () in
let title = create_title () in
title##.display := Js._true;
title##.text := Indexable.of_single @@ Js.string "Bar Chart";
(* Initialize tooltips *)
let tooltips = createTooltip () in
let tooltips = create_tooltip () in
tooltips##.mode := Interaction_mode.index;
tooltips##.intersect := Js._false;
(* Initialize other options *)
let options = createBarOptions () in
let options = create_bar_options () in
options##.title := title;
options##.tooltips := tooltips;
options##.maintainAspectRatio := Js._false;
Expand Down
58 changes: 28 additions & 30 deletions examples/line/line.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@ open Chartjs
let log x : unit = Js.Unsafe.global##.console##log x

let () =
let dataset1 =
createLineDataset
@@ Js.array [|10.; 15.; 30.; 20.; 25.; 10.; 7.|] in
(* Create first dataset. *)
let dataset1 = create_line_dataset () in
dataset1##.data := Js.array [|10.; 15.; 30.; 20.; 25.; 10.; 7.|];
dataset1##.borderColor := Color.of_string "red";
dataset1##.backgroundColor := Color.of_string "rgba(255, 0, 0, 0.4)";
dataset1##.label := Js.string "Dataset 1";
dataset1##.pointStyle := Point_style.star;
dataset1##.pointRadius := Scriptable_indexable.of_single 10;
dataset1##.pointBorderWidth := Scriptable_indexable.of_single 2;
let dataset2 =
createLineDataset
@@ Js.array [|20.; 10.; nan; 15.; 5.; 7.; 30.|] in
(* Create second dataset. *)
let dataset2 = create_line_dataset () in
dataset2##.data := Js.array [|20.; 10.; nan; 15.; 5.; 7.; 30.|];
dataset2##.borderColor := Color.of_string "blue";
dataset2##.backgroundColor := Color.of_string "rgba(0, 0, 255, 0.4)";
dataset2##.label := Js.string "Dataset 2";
dataset2##.spanGaps := Js._false;
dataset2##.pointStyle := Point_style.rectRot;
dataset2##.pointRadius := Scriptable_indexable.of_single 10;
dataset2##.pointBorderWidth := Scriptable_indexable.of_single 2;
(* Create chart data. *)
let labels =
List.map Js.string
[ "January"
; "February"
; "March"
; "April"
; "May"
; "June"
; "July"
] in
let data = createData
~datasets:[dataset1; dataset2]
~labels
() in
Array.map Js.string
[| "January"
; "February"
; "March"
; "April"
; "May"
; "June"
; "July"
|] in
let data = create_data () in
data##.datasets := Js.array [|dataset1; dataset2|];
data##.labels := Js.array labels;
(* Initialize legend *)
let legend_labels = createLegendLabels () in
let legend = createLegend () in
let legend_labels = create_legend_labels () in
let legend = create_legend () in
legend_labels##.fontSize := 12;
legend_labels##.fontColor := Color.of_string "blue";
legend_labels##.fontStyle := Js.string "bold";
Expand All @@ -50,7 +50,7 @@ let () =
legend##.reverse := Js._true;
legend##.labels := legend_labels;
(* Initialize title *)
let title = createTitle () in
let title = create_title () in
title##.display := Js._true;
title##.fontFamily := Js.string "monospace";
title##.fontColor := Js.string "indigo";
Expand All @@ -61,22 +61,20 @@ let () =
title##.position := Position.left;
title##.text := Indexable.of_list [Js.string "Title"; Js.string "subtitle"];
(* Initialize tooltips *)
let tooltips = createTooltip () in
let tooltips = create_tooltip () in
tooltips##.mode := Interaction_mode.index;
tooltips##.intersect := Js._false;
tooltips##.backgroundColor := Color.of_string "lime";
tooltips##.titleFontStyle := Js.string "italic";
(* Initialize scales *)
let axis = createCategoryCartesianAxis () in
let scales = createLineScales ~xAxes:[axis] () in
let axis = create_category_cartesian_axis () in
let scales = create_line_scales () in
axis##.display := Axis_display.auto;
scales##.xAxes := Js.array [|axis|];
(* Initialize other options *)
let options = createLineOptions () in
let options = create_line_options () in
(Js.Unsafe.coerce options)##.scales := scales;
options##.legend := legend;
options##.title := title;
options##.tooltips := tooltips;
options##.maintainAspectRatio := Js._false;
log options;
let chart = chart_from_id Chart.line (Js.Unsafe.coerce data) options "chart" in
let chart = chart_from_id Chart.line data options "chart" in
Js.Unsafe.global##.chart := chart
23 changes: 12 additions & 11 deletions examples/pie/pie.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ let () =
| 1 -> "lightblue"
| 2 -> "lightgreen"
| _ -> "initial)" in
let dataset = createPieDataset (Js.array [|40; 15; 20|]) in
(* Create dataset. *)
let dataset = create_pie_dataset () in
dataset##.data := Js.array [|40; 15; 20|];
dataset##.borderColor := Scriptable_indexable.of_fun border_color_fun;
dataset##.backgroundColor := Scriptable_indexable.of_fun background_color_fun;
dataset##.borderWidth := Scriptable_indexable.of_single 5;
dataset##.label := Js.string "Dataset 1";
let data = createData
~datasets:[dataset]
~labels:["first"; "second"; "third"]
() in
let legend = createLegend () in
let animation = createPieAnimation () in
let options = createPieOptions () in
(* Create chart data. *)
let data = create_data () in
data##.datasets := Js.array [|dataset|];
data##.labels := Js.array @@ Array.map Js.string [|"first"; "second"; "third"|];
let legend = create_legend () in
let animation = create_pie_animation () in
let options = create_pie_options () in
animation##.animateScale := Js._true;
animation##.animateRotate := Js._true;
legend##.position := Position.left;
Expand All @@ -38,6 +40,5 @@ let () =
options##.cutoutPercentage := 20.;
options##.animation := animation;
options##.legend := legend;
let pie = chart_from_id Chart.doughnut (Js.Unsafe.coerce data) options "chart" in
Js.Unsafe.global##.chart := pie;
Dom.appendChild Dom_html.document##.body pie##.canvas
let pie = chart_from_id Chart.doughnut data options "chart" in
Js.Unsafe.global##.chart := pie
72 changes: 32 additions & 40 deletions examples/timescale/timescale.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,71 @@ let log x : unit = Js.Unsafe.global##.console##log x

let format = "MM/DD/YYYY HH:mm"

let new_date days =
((Js.Unsafe.global##moment)##add days (Js.string "d"))##toDate

let new_date_string days =
((Js.Unsafe.global##moment)##add days (Js.string "d"))##format
(Js.string format)
let new_date year = Time.of_array [|year|]

let random () = Random.int 10

let () =
Random.init (Float.to_int (new%js Js.date_now)##getTime);
let dataset1 =
createLineDataset
@@ Js.array
@@ Array.init 7 (fun _ -> random ()) in
let dataset1 = create_line_dataset () in
dataset1##.data := Js.array @@ Array.init 7 (fun _ -> random ());
dataset1##.label := Js.string "My First Dataset";
dataset1##.backgroundColor := Color.of_string "rgba(255, 0, 0, 0.5)";
dataset1##.borderColor := Color.of_string "red";
dataset1##.fill := Line_fill._false;
let dataset2 =
createLineDataset
@@ Js.array
@@ Array.init 7 (fun _ -> random ()) in
let dataset2 = create_line_dataset () in
dataset2##.data := Js.array @@ Array.init 7 (fun _ -> random ());
dataset2##.label := Js.string "My Second Dataset";
dataset2##.backgroundColor := Color.of_string "rgba(0, 0, 255, 0.5)";
dataset2##.borderColor := Color.of_string "blue";
dataset2##.fill := Line_fill._false;
let dataset3 =
createLineDataset
@@ Js.array
@@ [| createDataPoint ~x:(new_date_string 0) ~y:(random ())
; createDataPoint ~x:(new_date_string 5) ~y:(random ())
; createDataPoint ~x:(new_date_string 7) ~y:(random ())
; createDataPoint ~x:(new_date_string 15) ~y:(random ())
|] in
let dataset3 = create_line_dataset () in
dataset3##.data :=
Js.array
@@ [| create_data_point ~x:(new_date 1990) ~y:(random ())
; create_data_point ~x:(new_date 1992) ~y:(random ())
; create_data_point ~x:(new_date 1994) ~y:(random ())
; create_data_point ~x:(new_date 1996) ~y:(random ())
|];
dataset3##.label := Js.string "Dataset with point data";
dataset3##.backgroundColor := Color.of_string "rgba(0, 255, 0, 0.5)";
dataset3##.borderColor := Color.of_string "green";
dataset3##.fill := Line_fill._false;
let data = createData
~labels:[ new_date 0
; new_date 1
; new_date 2
; new_date 3
; new_date 4
; new_date 5
; new_date 6 ]
~datasets:[ coerce_dataset dataset1
; coerce_dataset dataset2
; coerce_dataset dataset3 ]
() in
let data = create_data () in
data##.labels := Js.array [| new_date 1990
; new_date 1991
; new_date 1992
; new_date 1993
; new_date 1994
; new_date 1995
; new_date 1996 |];
data##.datasets := Js.array [| coerce_dataset dataset1
; coerce_dataset dataset2
; coerce_dataset dataset3 |];
(* Initialize title *)
let title = createTitle () in
let title = create_title () in
title##.display := Js._true;
title##.text := Indexable.of_single @@ Js.string "Chart.js Time Scale";
(* Initialize scales *)
let time = createTimeCartesianOptions () in
let time = create_time_cartesian_options () in
let (scaleLabel : scaleLabel Js.t) = Js.Unsafe.obj [||] in
let xAxis = createTimeCartesianAxis () in
let xAxis = create_time_cartesian_axis () in
time##._parser := Time_parser.of_string format;
time##.tooltipFormat := Js.string "ll HH:mm";
scaleLabel##.display := Js._true;
scaleLabel##.labelString := Js.string "Date";
xAxis##.time := time;
xAxis##.scaleLabel := scaleLabel;
let yAxis = createCartesianAxis () in
let yAxis = create_cartesian_axis () in
let (scaleLabel : scaleLabel Js.t) = Js.Unsafe.obj [||] in
scaleLabel##.display := Js._true;
scaleLabel##.labelString := Js.string "value";
yAxis##.scaleLabel := scaleLabel;
let scales = createLineScales ~xAxes:[xAxis] ~yAxes:[yAxis] () in
let scales = create_line_scales () in
scales##.xAxes := Js.array [|xAxis|];
scales##.yAxes := Js.array [|yAxis|];
(* Initialize other options *)
let options = createLineOptions () in
let options = create_line_options () in
options##.scales := scales;
options##.title := title;
options##.maintainAspectRatio := Js._false;
Expand Down
Loading

0 comments on commit e902990

Please sign in to comment.