Skip to content

Commit

Permalink
reimplemented datalabels plugin bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
monstasat committed Aug 14, 2019
1 parent 8cbfd21 commit 2cadeff
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 177 deletions.
3 changes: 2 additions & 1 deletion chartjs-datalabels._opam → chartjs-datalabels.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ build: [
depends: [
"ocaml" {>= "4.06.0"}
"dune" {build}
"gen_js_api"
"js_of_ocaml"
"js_of_ocaml-ppx"
]
9 changes: 0 additions & 9 deletions datalabels/_dune

This file was deleted.

165 changes: 0 additions & 165 deletions datalabels/chartjs_datalabels.mli

This file was deleted.

154 changes: 154 additions & 0 deletions plugins/datalabels/chartjs_datalabels.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
open Js_of_ocaml
open Chartjs

module Align = struct
type t

let center = Js.Unsafe.coerce @@ Js.string "center"

let start = Js.Unsafe.coerce @@ Js.string "start"

let _end = Js.Unsafe.coerce @@ Js.string "end"

let right = Js.Unsafe.coerce @@ Js.string "right"

let bottom = Js.Unsafe.coerce @@ Js.string "bottom"

let left = Js.Unsafe.coerce @@ Js.string "left"

let top = Js.Unsafe.coerce @@ Js.string "top"

let degree x = Js.Unsafe.coerce @@ Js.number_of_float x
end

module Anchor = struct
type t = Js.js_string

let center = Js.string "center"

let start = Js.string "start"

let _end = Js.string "end"
end

module Visibility = struct
type t

let of_bool x = Js.Unsafe.coerce @@ Js.bool x

let auto = Js.Unsafe.coerce @@ Js.string "auto"
end

module Text_align = struct
type t

let start = Js.Unsafe.coerce @@ Js.string "start"

let center = Js.Unsafe.coerce @@ Js.string "center"

let _end = Js.Unsafe.coerce @@ Js.string "end"

let left = Js.Unsafe.coerce @@ Js.string "left"

let right = Js.Unsafe.coerce @@ Js.string "right"
end

class type font = object
method family : Js.js_string Js.t Js.optdef_prop

method size : int Js.optdef_prop

method style : Js.js_string Js.t Js.optdef_prop

method weight : Js.js_string Js.t Js.optdef_prop

method lineHeight : Line_height.t Js.t Js.optdef_prop
end

class type optionContext = object
method active : bool Js.t Js.readonly_prop

method chart : 'a chart Js.t Js.readonly_prop

method dataIndex : int Js.readonly_prop

method dataset : dataset Js.t Js.readonly_prop

method datasetIndex : int Js.readonly_prop
end

class type listeners = object
method enter : (optionContext Js.t -> bool Js.t) Js.callback Js.optdef_prop

method leave : (optionContext Js.t -> bool Js.t) Js.callback Js.optdef_prop

method click : (optionContext Js.t -> bool Js.t) Js.callback Js.optdef_prop
end

type 'a prop = (optionContext, 'a) Scriptable_indexable.t Js.t

type 'a formatter = ('a -> optionContext Js.t -> Js.js_string Js.t) Js.callback

class type datalabels = object
method align : Align.t Js.t prop Js.optdef_prop

method anchor : Anchor.t Js.t prop Js.optdef_prop

method backgroundColor : Color.t Js.t Js.opt prop Js.optdef_prop

method borderColor : Color.t Js.t Js.opt prop Js.optdef_prop

method borderRadius : int prop Js.optdef_prop

method borderWidth : int prop Js.optdef_prop

method clamp : bool Js.t prop Js.optdef_prop

method clip : bool Js.t prop Js.optdef_prop

method color : Color.t Js.t prop Js.optdef_prop

method display : Visibility.t Js.t prop Js.optdef_prop

method font : font Js.t prop Js.optdef_prop

method formatter : 'a formatter Js.opt Js.optdef_prop

method listeners : listeners Js.t Js.optdef_prop

method offset : float prop Js.optdef_prop

method opacity : float prop Js.optdef_prop

method padding : Padding.t Js.t prop Js.optdef_prop

method rotation : float prop Js.optdef_prop

method textAlign : Text_align.t Js.t prop Js.optdef_prop

method textStrokeColor : Color.t Js.t prop Js.optdef_prop

method textStrokeWidth : int prop Js.optdef_prop

method textShadowBlur : float prop Js.optdef_prop

method textShadowColor : Color.t Js.t prop Js.optdef_prop
end

let of_dataset dataset =
(Js.Unsafe.coerce dataset)##.datalabels

let of_chart chart =
(Js.Unsafe.coerce chart)##.options##.plugins##.datalabels

let of_global () =
Js.Unsafe.global##._Chart##.defaults##.global##.plugins##.datalabels

let set_per_dataset dataset plugin =
(Js.Unsafe.coerce dataset)##.realtime := plugin

let set_per_chart chart plugin =
(Js.Unsafe.coerce chart)##.options##.plugins##.datalabels := plugin

let set_globally plugin =
Js.Unsafe.global##._Chart##.defaults##.global##.plugins##.datalabels := plugin
Loading

0 comments on commit 2cadeff

Please sign in to comment.