diff --git a/python/python.ml b/python/python.ml index 2ec1ef4..5935bd6 100644 --- a/python/python.ml +++ b/python/python.ml @@ -23,17 +23,35 @@ type _ t = Py.Object.t type figure -let of_graph Graph.{type_; data} = +let of_graph ?(z = [||]) ?text Graph.{type_; data} = let c = match type_ with | "scatter" -> "Scatter" | "scatter3d" -> "Scatter3d" + | "scattergl" -> "Scattergl" | "bar" -> "Bar" | "pie" -> "Pie" | _ -> assert false in + let base_attributes = of_attributes (data :> Attribute.t list) in + let marker_attributes = Some [ + "colorscale", Py.String.of_string "Viridis"; + "color", Py.List.of_array_map Py.Float.of_float z; + "size", Py.Int.of_int 1; + ] + in + let py_attributes = + List.concat [ + base_attributes; + (Option.fold ~none:[] ~some:(fun l -> + [ "marker", Py.Dict.of_bindings_string l ]) marker_attributes); + (Option.fold ~none:[] ~some:(fun a -> + [ "text", Py.List.of_array_map Py.String.of_string a ] + ) text) + ] + in Py.Module.get_function_with_keywords go c [||] - (of_attributes (data :> Attribute.t list)) + py_attributes let of_layout layout = let layout = (layout : Layout.t :> Attribute.t list) in @@ -42,8 +60,8 @@ let of_layout layout = of_value layout -let of_figure fig : figure t = - let data = Py.List.of_list_map of_graph fig.Figure.graphs in +let of_figure ?z ?text fig : figure t = + let data = Py.List.of_list_map (of_graph ?z ?text) fig.Figure.graphs in let layout = of_layout fig.layout in Py.Module.get_function_with_keywords go "Figure" [||] ["data", data; diff --git a/python/python.mli b/python/python.mli index ffc2007..1d9580d 100644 --- a/python/python.mli +++ b/python/python.mli @@ -2,7 +2,7 @@ type _ t = private Py.Object.t type figure -val of_figure : Plotly.Figure.t -> figure t +val of_figure : ?z:float array -> ?text:string array -> Plotly.Figure.t -> figure t val show : ?renderer:string -> figure t -> unit val write_image : figure t -> string -> unit diff --git a/src/plotly.ml b/src/plotly.ml index 417adb9..ab72989 100644 --- a/src/plotly.ml +++ b/src/plotly.ml @@ -51,6 +51,7 @@ module Graph = struct let scatter data_list = { type_ = "scatter"; data= List.flatten data_list } let scatter3d data_list = { type_ = "scatter3d"; data= List.flatten data_list } + let scattergl data_list = { type_ = "scattergl"; data= List.flatten data_list } let bar data_list = { type_ = "bar"; data= List.flatten data_list } let pie data_list = { type_ = "pie"; data= List.flatten data_list } let histogram data_list = { type_ = "histogram"; data= List.flatten data_list } diff --git a/src/plotly.mli b/src/plotly.mli index 3e9033a..a17b299 100644 --- a/src/plotly.mli +++ b/src/plotly.mli @@ -77,6 +77,7 @@ module Graph : sig val scatter : Data.t list -> t val scatter3d : Data.t list -> t + val scattergl : Data.t list -> t val bar : Data.t list -> t val pie : Data.t list -> t val histogram : Data.t list -> t