From e902990327ff99bffff13fbfc48d0bc9c550369f Mon Sep 17 00:00:00 2001 From: monstasat Date: Wed, 14 Aug 2019 16:01:02 +0300 Subject: [PATCH] camelCase -> snake_case --- TODO.md | 4 +- chartjs-datalabels.opam | 1 + chartjs-streaming.opam | 1 + examples/bar/bar.ml | 48 +++---- examples/line/line.ml | 58 ++++---- examples/pie/pie.ml | 23 ++-- examples/timescale/timescale.ml | 72 +++++----- lib/chartjs.ml | 154 ++++++++-------------- lib/chartjs.mli | 137 ++++++++----------- plugins/datalabels/chartjs_datalabels.ml | 2 + plugins/datalabels/chartjs_datalabels.mli | 2 + plugins/streaming/chartjs_streaming.ml | 6 +- plugins/streaming/chartjs_streaming.mli | 2 +- 13 files changed, 214 insertions(+), 296 deletions(-) diff --git a/TODO.md b/TODO.md index 937c66a..2d1a909 100644 --- a/TODO.md +++ b/TODO.md @@ -7,6 +7,6 @@ ## Plugins * [ ] Crosshair - * [ ] Datalabels - * [ ] Streaming + * [X] Datalabels + * [X] Streaming * [ ] Deferred diff --git a/chartjs-datalabels.opam b/chartjs-datalabels.opam index b66bc56..fbddc2c 100644 --- a/chartjs-datalabels.opam +++ b/chartjs-datalabels.opam @@ -19,4 +19,5 @@ depends: [ "dune" {build} "js_of_ocaml" "js_of_ocaml-ppx" + "chartjs" ] diff --git a/chartjs-streaming.opam b/chartjs-streaming.opam index cc22c57..0e6c6a7 100644 --- a/chartjs-streaming.opam +++ b/chartjs-streaming.opam @@ -19,4 +19,5 @@ depends: [ "dune" {build} "js_of_ocaml" "js_of_ocaml-ppx" + "chartjs" ] diff --git a/examples/bar/bar.ml b/examples/bar/bar.ml index 8106ef5..798f98c 100644 --- a/examples/bar/bar.ml +++ b/examples/bar/bar.ml @@ -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; diff --git a/examples/line/line.ml b/examples/line/line.ml index 11a6a84..65c7b79 100644 --- a/examples/line/line.ml +++ b/examples/line/line.ml @@ -4,18 +4,18 @@ 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"; @@ -23,23 +23,23 @@ let () = 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"; @@ -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"; @@ -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 diff --git a/examples/pie/pie.ml b/examples/pie/pie.ml index b43a7fe..7be3986 100644 --- a/examples/pie/pie.ml +++ b/examples/pie/pie.ml @@ -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; @@ -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 diff --git a/examples/timescale/timescale.ml b/examples/timescale/timescale.ml index d15f814..f38d0a2 100644 --- a/examples/timescale/timescale.ml +++ b/examples/timescale/timescale.ml @@ -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; diff --git a/lib/chartjs.ml b/lib/chartjs.ml index 827cbfb..1a3df93 100644 --- a/lib/chartjs.ml +++ b/lib/chartjs.ml @@ -571,35 +571,33 @@ class type ['x, 'y] dataPoint = object method y : 'y Js.prop end -class type ['t, 'y] timeDataPoint = object +class type ['t, 'y] dataPointT = object method t : 't Js.prop method y : 'y Js.prop end -class type ['x, 'y, 'r] bubbleDataPoint = object - method x : 'x Js.prop - - method y : 'y Js.prop +class type ['x, 'y, 'r] dataPointR = object + inherit ['x, 'y] dataPoint method r : 'r Js.prop end -let createDataPoint ~x ~y = +let create_data_point ~x ~y = object%js val mutable x = x val mutable y = y end -let createTimeDataPoint ~t ~y = +let create_data_point_t ~t ~y = object%js val mutable t = t val mutable y = y end -let createBubbleDataPoint ~x ~y ~r = +let create_data_point_r ~x ~y ~r = object%js val mutable x = x @@ -731,37 +729,15 @@ class type axis = object method afterUpdate : ('a Js.t -> unit) Js.callback Js.optdef_prop end -let createMinorTicks () = Js.Unsafe.obj [||] +let create_minor_ticks () = Js.Unsafe.obj [||] -let createMajorTicks () = Js.Unsafe.obj [||] +let create_major_ticks () = Js.Unsafe.obj [||] -let createTicks () = Js.Unsafe.obj [||] +let create_ticks () = Js.Unsafe.obj [||] -let createScaleLabel () = Js.Unsafe.obj [||] +let create_scale_label () = Js.Unsafe.obj [||] -let createGridLines ?display ?circular ?color ?borderDash ?borderDashOffset - ?lineWidth ?drawBorder ?drawOnChartArea ?drawTicks ?tickMarkLength - ?zeroLineWidth ?zeroLineColor ?zeroLineBorderDash ?zeroLineBorderDashOffset - ?offsetGridLines () = - let (obj : gridLines Js.t) = Js.Unsafe.obj [||] in - iter (fun x -> obj##.display := Js.bool x) display; - iter (fun x -> obj##.circular := Js.bool x) circular; - iter (fun x -> obj##.color := x) color; - iter (fun x -> obj##.borderDash := x) borderDash; - iter (fun x -> obj##.borderDashOffset := x) borderDashOffset; - iter (fun x -> obj##.lineWidth := x) lineWidth; - iter (fun x -> obj##.drawBorder := Js.bool x) drawBorder; - iter (fun x -> obj##.drawOnChartArea := Js.bool x) drawOnChartArea; - iter (fun x -> obj##.drawTicks := Js.bool x) drawTicks; - iter (fun x -> obj##.tickMarkLength := x) tickMarkLength; - iter (fun x -> obj##.zeroLineWidth := x) zeroLineWidth; - iter (fun x -> obj##.zeroLineColor := x) zeroLineColor; - iter (fun x -> obj##.zeroLineBorderDash := x) zeroLineBorderDash; - iter (fun x -> obj##.zeroLineBorderDashOffset := x) zeroLineBorderDashOffset; - iter (fun x -> obj##.offsetGridLines := Js.bool x) offsetGridLines; - obj - -let createAxis () = Js.Unsafe.obj [||] +let create_grid_lines () = Js.Unsafe.obj [||] class type cartesianTicks = object inherit ticks @@ -797,7 +773,7 @@ class type ['a] cartesianAxis = object method ticks : (#cartesianTicks as 'a) Js.t Js.prop end -let createCartesianAxis () = Js.Unsafe.obj [||] +let create_cartesian_axis () = Js.Unsafe.obj [||] (** {3 Category axis} *) @@ -813,9 +789,9 @@ end class type categoryCartesianAxis = [categoryCartesianTicks] cartesianAxis -let createCategoryCartesianTicks () = Js.Unsafe.obj [||] +let create_category_cartesian_ticks () = Js.Unsafe.obj [||] -let createCategoryCartesianAxis () = +let create_category_cartesian_axis () = let (axis : categoryCartesianAxis Js.t) = Js.Unsafe.obj [||] in axis##._type := Js.string "category"; axis @@ -842,9 +818,9 @@ end class type linearCartesianAxis = [linearCartesianTicks] cartesianAxis -let createLinearCartesianTicks () = Js.Unsafe.obj [||] +let create_linear_cartesian_ticks () = Js.Unsafe.obj [||] -let createLinearCartesianAxis () = +let create_linear_cartesian_axis () = let (axis : linearCartesianAxis Js.t) = Js.Unsafe.obj [||] in axis##._type := Js.string "linear"; axis @@ -859,9 +835,9 @@ end class type logarithmicCartesianAxis = [logarithmicCartesianTicks] cartesianAxis -let createLogarithmicCartesianTicks () = Js.Unsafe.obj [||] +let create_logarithmic_cartesian_ticks () = Js.Unsafe.obj [||] -let createLogarithmicCartesianAxis () = +let create_logarithmic_cartesian_axis () = let (axis : logarithmicCartesianAxis Js.t) = Js.Unsafe.obj [||] in axis##._type := Js.string "logarithmic"; axis @@ -924,13 +900,13 @@ class type timeCartesianAxis = object method bounds : Time_bounds.t Js.prop end -let createTimeDisplayFormats () = Js.Unsafe.obj [||] +let create_time_display_formats () = Js.Unsafe.obj [||] -let createTimeCartesianTicks () = Js.Unsafe.obj [||] +let create_time_cartesian_ticks () = Js.Unsafe.obj [||] -let createTimeCartesianOptions () = Js.Unsafe.obj [||] +let create_time_cartesian_options () = Js.Unsafe.obj [||] -let createTimeCartesianAxis () = +let create_time_cartesian_axis () = let (axis : timeCartesianAxis Js.t) = Js.Unsafe.obj [||] in axis##._type := Js.string "time"; axis @@ -944,7 +920,7 @@ end let coerce_dataset x = (x :> dataset Js.t) class type data = object - method datasets : dataset Js.t Js.js_array Js.t Js.prop + method datasets : #dataset Js.t Js.js_array Js.t Js.prop method labels : 'a Js.js_array Js.t Js.optdef_prop @@ -953,18 +929,7 @@ class type data = object method yLabels : 'a Js.js_array Js.t Js.optdef_prop end -let createData ?(datasets = []) ?labels ?xLabels ?yLabels () = - let map_labels x = Js.array @@ Array.of_list x in - let (obj : data Js.t) = Js.Unsafe.obj [||] in - iter (fun x -> obj##.labels := map_labels x) labels; - iter (fun x -> obj##.xLabels := map_labels x) xLabels; - iter (fun x -> obj##.yLabels := map_labels x) yLabels; - let datasets = - Js.array - @@ Array.of_list - @@ List.map (fun x -> (x :> dataset Js.t)) datasets in - obj##.datasets := datasets; - obj +let create_data () = Js.Unsafe.obj [||] class type ['chart] animationItem = object method chart : 'chart Js.t Js.readonly_prop @@ -990,13 +955,13 @@ class type ['chart] animation = object method onComplete : ('chart animationItem Js.t -> unit) Js.callback Js.opt Js.prop end -let createAnimation () = Js.Unsafe.obj [||] +let create_animation () = Js.Unsafe.obj [||] class type layout = object method padding : Padding.t Js.prop end -let createLayout () = Js.Unsafe.obj [||] +let create_layout () = Js.Unsafe.obj [||] class type legendItem = object method text : Js.js_string Js.t Js.prop @@ -1078,9 +1043,9 @@ class type ['chart] legend = object method labels : 'chart legendLabels Js.t Js.prop end -let createLegendLabels () = Js.Unsafe.obj [||] +let create_legend_labels () = Js.Unsafe.obj [||] -let createLegend () = Js.Unsafe.obj [||] +let create_legend () = Js.Unsafe.obj [||] class type title = object method display : bool Js.t Js.prop @@ -1104,7 +1069,7 @@ class type title = object method text : Js.js_string Js.t Indexable.t Js.t Js.prop end -let createTitle () = Js.Unsafe.obj [||] +let create_title () = Js.Unsafe.obj [||] class type tooltipItem = object method label : Js.js_string Js.t Js.readonly_prop @@ -1373,7 +1338,7 @@ and ['chart] tooltip = object('self) method borderWidth : int Js.prop end -let createTooltip () = Js.Unsafe.obj [||] +let create_tooltip () = Js.Unsafe.obj [||] class type hover = object method mode : Interaction_mode.t Js.prop @@ -1385,7 +1350,7 @@ class type hover = object method animationDuration : int Js.prop end -let createHover () = Js.Unsafe.obj [||] +let create_hover () = Js.Unsafe.obj [||] class type pointElement = object method radius : int Js.prop @@ -1461,15 +1426,15 @@ class type elements = object method arc : arcElement Js.t Js.prop end -let createPointElement () = Js.Unsafe.obj [||] +let create_point_element () = Js.Unsafe.obj [||] -let createLineElement () = Js.Unsafe.obj [||] +let create_line_element () = Js.Unsafe.obj [||] -let createRectangleElement () = Js.Unsafe.obj [||] +let create_rectangle_element () = Js.Unsafe.obj [||] -let createArcElement () = Js.Unsafe.obj [||] +let create_arc_element () = Js.Unsafe.obj [||] -let createElements () = Js.Unsafe.obj [||] +let create_elements () = Js.Unsafe.obj [||] class type chartSize = object method width : int Js.readonly_prop @@ -1485,7 +1450,7 @@ class type updateConfig = object method easing : Easing.t Js.optdef_prop end -let createUpdateConfig ?duration ?_lazy ?easing () : updateConfig Js.t = +let create_update_config ?duration ?_lazy ?easing () : updateConfig Js.t = let (conf : updateConfig Js.t) = Js.Unsafe.obj [||] in iter (fun x -> conf##.duration := x) duration; iter (fun x -> conf##._lazy := Js.bool x) _lazy; @@ -1503,6 +1468,8 @@ class type ['chart, 'animation] chartOptions = object method title : title Js.t Js.prop + method hover : hover Js.t Js.prop + method tooltips : 'chart tooltip Js.t Js.prop method elements : elements Js.t Js.prop @@ -1699,18 +1666,11 @@ and lineChart = object inherit [lineOptions] chart end -let createLineScales ?xAxes ?yAxes () = - let (scales : lineScales Js.t) = Js.Unsafe.obj [||] in - iter (fun x -> scales##.xAxes := Js.array @@ Array.of_list x) xAxes; - iter (fun x -> scales##.yAxes := Js.array @@ Array.of_list x) yAxes; - scales +let create_line_scales () = Js.Unsafe.obj [||] -let createLineOptions () = Js.Unsafe.obj [||] +let create_line_options () = Js.Unsafe.obj [||] -let createLineDataset data : 'a lineDataset Js.t = - let (lineDataset : 'a lineDataset Js.t) = Js.Unsafe.obj [||] in - lineDataset##.data := data; - lineDataset +let create_line_dataset () = Js.Unsafe.obj [||] class type barAxis = object method barPercentage : float Js.prop @@ -1804,26 +1764,19 @@ and barChart = object inherit [barOptions] chart end -let createCategoryBarAxis () = Js.Unsafe.obj [||] +let create_category_bar_axis () = Js.Unsafe.obj [||] -let createLinearBarAxis () = Js.Unsafe.obj [||] +let create_linear_bar_axis () = Js.Unsafe.obj [||] -let createLogarithmicBarAxis () = Js.Unsafe.obj [||] +let create_logarithmic_bar_axis () = Js.Unsafe.obj [||] -let createTimeBarAxis () = Js.Unsafe.obj [||] +let create_time_bar_axis () = Js.Unsafe.obj [||] -let createBarScales ?xAxes ?yAxes () = - let (scales : barScales Js.t) = Js.Unsafe.obj [||] in - iter (fun x -> scales##.xAxes := Js.array @@ Array.of_list x) xAxes; - iter (fun x -> scales##.yAxes := Js.array @@ Array.of_list x) yAxes; - scales +let create_bar_scales () = Js.Unsafe.obj [||] -let createBarOptions () = Js.Unsafe.obj [||] +let create_bar_options () = Js.Unsafe.obj [||] -let createBarDataset data : 'a barDataset Js.t = - let (barDataset : 'a barDataset Js.t) = Js.Unsafe.obj [||] in - barDataset##.data := data; - barDataset +let create_bar_dataset () = Js.Unsafe.obj [||] class type ['a] pieOptionContext = object method chart : pieChart Js.t Js.readonly_prop @@ -1885,14 +1838,11 @@ and pieChart = object inherit [pieOptions] chart end -let createPieAnimation () = Js.Unsafe.obj [||] +let create_pie_animation () = Js.Unsafe.obj [||] -let createPieOptions () = Js.Unsafe.obj [||] +let create_pie_options () = Js.Unsafe.obj [||] -let createPieDataset data : 'a pieDataset Js.t = - let (pieDataset : 'a pieDataset Js.t) = Js.Unsafe.coerce @@ Js.Unsafe.obj [||] in - pieDataset##.data := data; - pieDataset +let create_pie_dataset () = Js.Unsafe.obj [||] module Axis = struct type 'a typ = Js.js_string Js.t diff --git a/lib/chartjs.mli b/lib/chartjs.mli index 434899a..46a405b 100644 --- a/lib/chartjs.mli +++ b/lib/chartjs.mli @@ -543,25 +543,23 @@ class type ['x, 'y] dataPoint = object method y : 'y Js.prop end -class type ['t, 'y] timeDataPoint = object +class type ['t, 'y] dataPointT = object method t : 't Js.prop method y : 'y Js.prop end -class type ['x, 'y, 'r] bubbleDataPoint = object - method x : 'x Js.prop - - method y : 'y Js.prop +class type ['x, 'y, 'r] dataPointR = object + inherit ['x, 'y] dataPoint method r : 'r Js.prop end -val createDataPoint : x:'a -> y:'b -> ('a, 'b) dataPoint Js.t +val create_data_point : x:'a -> y:'b -> ('a, 'b) dataPoint Js.t -val createTimeDataPoint : t:'a -> y:'b -> ('a, 'b) timeDataPoint Js.t +val create_data_point_t : t:'a -> y:'b -> ('a, 'b) dataPointT Js.t -val createBubbleDataPoint : x:'a -> y:'b -> r:'c -> ('a, 'b, 'c) bubbleDataPoint Js.t +val create_data_point_r : x:'a -> y:'b -> r:'c -> ('a, 'b, 'c) dataPointR Js.t (** {1 Axes} *) @@ -774,34 +772,15 @@ class type axis = object (** Callback that runs at the end of the update process. *) end -val createMinorTicks : unit -> minorTicks Js.t +val create_minor_ticks : unit -> minorTicks Js.t -val createMajorTicks : unit -> majorTicks Js.t +val create_major_ticks : unit -> majorTicks Js.t -val createTicks : unit -> ticks Js.t +val create_ticks : unit -> ticks Js.t -val createScaleLabel : unit -> scaleLabel Js.t - -val createGridLines : - ?display:bool - -> ?circular:bool - -> ?color:Color.t Js.t Indexable.t Js.t - -> ?borderDash:line_dash - -> ?borderDashOffset:line_dash_offset - -> ?lineWidth:int Indexable.t Js.t - -> ?drawBorder:bool - -> ?drawOnChartArea:bool - -> ?drawTicks:bool - -> ?tickMarkLength:int - -> ?zeroLineWidth:int - -> ?zeroLineColor:Color.t Js.t - -> ?zeroLineBorderDash:line_dash - -> ?zeroLineBorderDashOffset:line_dash_offset - -> ?offsetGridLines:bool - -> unit - -> gridLines Js.t +val create_scale_label : unit -> scaleLabel Js.t -val createAxis : unit -> axis Js.t +val create_grid_lines : unit -> gridLines Js.t (** {2 Cartesian axes} *) @@ -867,7 +846,7 @@ class type ['a] cartesianAxis = object (** Tick configuration. *) end -val createCartesianAxis : unit -> 'a cartesianAxis Js.t +val create_cartesian_axis : unit -> 'a cartesianAxis Js.t (** {3 Category axis} *) @@ -886,9 +865,9 @@ end class type categoryCartesianAxis = [categoryCartesianTicks] cartesianAxis -val createCategoryCartesianTicks : unit -> categoryCartesianTicks Js.t +val create_category_cartesian_ticks : unit -> categoryCartesianTicks Js.t -val createCategoryCartesianAxis : unit -> categoryCartesianAxis Js.t +val create_category_cartesian_axis : unit -> categoryCartesianAxis Js.t (** {3 Linear axis} *) @@ -925,9 +904,9 @@ end class type linearCartesianAxis = [linearCartesianTicks] cartesianAxis -val createLinearCartesianTicks : unit -> linearCartesianTicks Js.t +val create_linear_cartesian_ticks : unit -> linearCartesianTicks Js.t -val createLinearCartesianAxis : unit -> linearCartesianAxis Js.t +val create_linear_cartesian_axis : unit -> linearCartesianAxis Js.t (** {3 Logarithmic axis} *) @@ -945,9 +924,9 @@ end class type logarithmicCartesianAxis = [logarithmicCartesianTicks] cartesianAxis -val createLogarithmicCartesianTicks : unit -> logarithmicCartesianTicks Js.t +val create_logarithmic_cartesian_ticks : unit -> logarithmicCartesianTicks Js.t -val createLogarithmicCartesianAxis : unit -> logarithmicCartesianAxis Js.t +val create_logarithmic_cartesian_axis : unit -> logarithmicCartesianAxis Js.t (** {3 Time axis} *) @@ -1034,13 +1013,13 @@ class type timeCartesianAxis = object [ticks]: makes sure ticks are fully visible, data outside are truncated *) end -val createTimeDisplayFormats : unit -> timeDisplayFormats Js.t +val create_time_display_formats : unit -> timeDisplayFormats Js.t -val createTimeCartesianTicks : unit -> timeCartesianTicks Js.t +val create_time_cartesian_ticks : unit -> timeCartesianTicks Js.t -val createTimeCartesianOptions : unit -> timeCartesianOptions Js.t +val create_time_cartesian_options : unit -> timeCartesianOptions Js.t -val createTimeCartesianAxis : unit -> timeCartesianAxis Js.t +val create_time_cartesian_axis : unit -> timeCartesianAxis Js.t class type dataset = object method _type : Js.js_string Js.t Js.optdef_prop @@ -1051,7 +1030,7 @@ end val coerce_dataset : #dataset Js.t -> dataset Js.t class type data = object - method datasets : dataset Js.t Js.js_array Js.t Js.prop + method datasets : #dataset Js.t Js.js_array Js.t Js.prop method labels : 'a Js.js_array Js.t Js.optdef_prop @@ -1060,13 +1039,7 @@ class type data = object method yLabels : 'a Js.js_array Js.t Js.optdef_prop end -val createData : - ?datasets:#dataset Js.t list - -> ?labels:'a list - -> ?xLabels:'a list - -> ?yLabels:'a list - -> unit - -> data Js.t +val create_data : unit -> data Js.t (** {1 Chart configuration} *) @@ -1106,7 +1079,7 @@ class type ['chart] animation = object (** Callback called at the end of an animation. *) end -val createAnimation : unit -> 'a animation Js.t +val create_animation : unit -> 'a animation Js.t (** {2 Layout} *) @@ -1115,7 +1088,7 @@ class type layout = object (** The padding to add inside the chart. *) end -val createLayout : unit -> layout Js.t +val create_layout : unit -> layout Js.t (** {2 Legend} *) @@ -1235,9 +1208,9 @@ class type ['chart] legend = object (** Legend label configuration. *) end -val createLegendLabels : unit -> 'a legendLabels Js.t +val create_legend_labels : unit -> 'a legendLabels Js.t -val createLegend : unit -> 'a legend Js.t +val create_legend : unit -> 'a legend Js.t (** {2 Title} *) @@ -1273,7 +1246,7 @@ class type title = object text is rendered on multiple lines. *) end -val createTitle : unit -> title Js.t +val create_title : unit -> title Js.t (** {2 Tooltip} *) @@ -1590,7 +1563,7 @@ and ['chart] tooltip = object('self) (** Size of the border. *) end -val createTooltip : unit -> 'a tooltip Js.t +val create_tooltip : unit -> 'a tooltip Js.t (** {2 Interactions} *) @@ -1611,7 +1584,7 @@ class type hover = object (** Duration in milliseconds it takes to animate hover style changes. *) end -val createHover : unit -> hover Js.t +val create_hover : unit -> hover Js.t (** {2 Elements} *) @@ -1723,15 +1696,15 @@ class type elements = object (** Arcs are used in the polar area, doughnut and pie charts. *) end -val createPointElement : unit -> pointElement Js.t +val create_point_element : unit -> pointElement Js.t -val createLineElement : unit -> lineElement Js.t +val create_line_element : unit -> lineElement Js.t -val createRectangleElement : unit -> rectangleElement Js.t +val create_rectangle_element : unit -> rectangleElement Js.t -val createArcElement : unit -> arcElement Js.t +val create_arc_element : unit -> arcElement Js.t -val createElements : unit -> elements Js.t +val create_elements : unit -> elements Js.t (** {2 Options} *) @@ -1751,7 +1724,7 @@ end (** {2 Chart} *) -val createUpdateConfig : +val create_update_config : ?duration:int -> ?_lazy:bool -> ?easing:Easing.t @@ -1779,6 +1752,8 @@ class type ['chart, 'animation] chartOptions = object method title : title Js.t Js.prop (** The chart title defines text to draw at the top of the chart. *) + method hover : hover Js.t Js.prop + method tooltips : 'chart tooltip Js.t Js.prop method elements : elements Js.t Js.prop @@ -2100,15 +2075,11 @@ and lineChart = object inherit [lineOptions] chart end -val createLineScales : - ?xAxes:#cartesianTicks #cartesianAxis Js.t list - -> ?yAxes:#cartesianTicks #cartesianAxis Js.t list - -> unit - -> lineScales Js.t +val create_line_scales : unit -> lineScales Js.t -val createLineOptions : unit -> lineOptions Js.t +val create_line_options : unit -> lineOptions Js.t -val createLineDataset : 'a Js.js_array Js.t -> 'a lineDataset Js.t +val create_line_dataset : unit -> 'a lineDataset Js.t (** {2 Bar Chart} *) @@ -2249,23 +2220,19 @@ and barChart = object inherit [barOptions] chart end -val createCategoryBarAxis : unit -> cateroryBarAxis Js.t +val create_category_bar_axis : unit -> cateroryBarAxis Js.t -val createLinearBarAxis : unit -> linearBarAxis Js.t +val create_linear_bar_axis : unit -> linearBarAxis Js.t -val createLogarithmicBarAxis : unit -> logarithmicBarAxis Js.t +val create_logarithmic_bar_axis : unit -> logarithmicBarAxis Js.t -val createTimeBarAxis : unit -> timeBarAxis Js.t +val create_time_bar_axis : unit -> timeBarAxis Js.t -val createBarScales : - ?xAxes:#barAxis Js.t list - -> ?yAxes:#barAxis Js.t list - -> unit - -> barScales Js.t +val create_bar_scales : unit -> barScales Js.t -val createBarOptions : unit -> barOptions Js.t +val create_bar_options : unit -> barOptions Js.t -val createBarDataset : 'a Js.js_array Js.t -> 'a barDataset Js.t +val create_bar_dataset : unit -> 'a barDataset Js.t (** {2 Pie Chart} *) @@ -2355,11 +2322,11 @@ and pieChart = object inherit [pieOptions] chart end -val createPieAnimation : unit -> pieAnimation Js.t +val create_pie_animation : unit -> pieAnimation Js.t -val createPieOptions : unit -> pieOptions Js.t +val create_pie_options : unit -> pieOptions Js.t -val createPieDataset : 'a Js.js_array Js.t -> 'a pieDataset Js.t +val create_pie_dataset : unit -> 'a pieDataset Js.t module Axis : sig type 'a typ diff --git a/plugins/datalabels/chartjs_datalabels.ml b/plugins/datalabels/chartjs_datalabels.ml index 2eca4dd..7295da3 100644 --- a/plugins/datalabels/chartjs_datalabels.ml +++ b/plugins/datalabels/chartjs_datalabels.ml @@ -135,6 +135,8 @@ class type datalabels = object method textShadowColor : Color.t Js.t prop Js.optdef_prop end +let create () = Js.Unsafe.obj [||] + let of_dataset dataset = (Js.Unsafe.coerce dataset)##.datalabels diff --git a/plugins/datalabels/chartjs_datalabels.mli b/plugins/datalabels/chartjs_datalabels.mli index 3f69768..25884cc 100644 --- a/plugins/datalabels/chartjs_datalabels.mli +++ b/plugins/datalabels/chartjs_datalabels.mli @@ -159,6 +159,8 @@ class type datalabels = object method textShadowColor : Color.t Js.t prop Js.optdef_prop end +val create : unit -> datalabels Js.t + (** {1 Positioning} {2 Anchoring} diff --git a/plugins/streaming/chartjs_streaming.ml b/plugins/streaming/chartjs_streaming.ml index 9fc56ab..2380775 100644 --- a/plugins/streaming/chartjs_streaming.ml +++ b/plugins/streaming/chartjs_streaming.ml @@ -26,7 +26,11 @@ class type streaming = object method pause : bool Js.t Js.optdef_prop end -let createUpdateConfig () = Js.Unsafe.obj [||] +let create_update_config ?preservation () = + let (obj : updateConfig Js.t) = Js.Unsafe.obj [||] in + match preservation with + | None -> obj + | Some p -> obj##.preservation := Js.bool p; obj let create ?duration ?ttl ?delay ?refresh ?onRefresh ?frameRate ?pause () = let iter f = function None -> () | Some x -> f x in diff --git a/plugins/streaming/chartjs_streaming.mli b/plugins/streaming/chartjs_streaming.mli index b0afd2d..f43fa51 100644 --- a/plugins/streaming/chartjs_streaming.mli +++ b/plugins/streaming/chartjs_streaming.mli @@ -53,7 +53,7 @@ class type streaming = object Note that onRefresh callback is called even when this is set to [true]. *) end -val createUpdateConfig : unit -> updateConfig Js.t +val create_update_config : ?preservation:bool -> unit -> updateConfig Js.t val create : ?duration:int