Skip to content

Commit

Permalink
v0.17~preview.129.17+77
Browse files Browse the repository at this point in the history
  • Loading branch information
public-release committed Apr 1, 2024
1 parent 406529e commit d5d79a9
Show file tree
Hide file tree
Showing 344 changed files with 10,858 additions and 10,422 deletions.
28 changes: 28 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
- Added a `duplicate` button for elements within auto-generated list forms.

- Added a function to resize prt colum widths.

- Add `Bonsai.Value.of_opt` to new `Bonsai.Cont` api.

- Migrated bonsai examples to new `Bonsai.Cont` API.

- Add documentation about changes and upgrade strategies between proc and cont

- Add 3 new APIs to close Bonsai notifications:
* `close_all_notifications` closes all currently open notifications
* `close_oldest_notification` closes the oldest currently open notification
* `close_newest_notification` closes the newest currently open notification

- Rename `Bonsai.Cont.yoink` to `Bonsai.Cont.peek` to mirror the peek operation in
other abstract data types

- Made the `close_when_clicked_outside` argument to `Bonsai_web_ui_popover` dynamic.

- Changed Bonsai path generation so that paths are only extended at branch points where
multple children might reference the paths.

- Balance long chains of Sub nodes to prevent stack overflows and suboptimal
linear chains of incremental model values.

- Added effects to lock and unlock focus in the `Bonsai_web_ui_partial_render_table`

- `Bonsai_web_ui_form` and `Bonsai_web_ui_form2` were merged into `Bonsai_web_ui_form` under
submodules `With_automatic_view` and `With_manual_view`, respectively.

Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Bonsai


Bonsai is a library for building interactive browser-based UI.

The [Getting Started with Bonsai](./docs/getting_started/index.md)
guide is good if you're new to web development entirely or just want to see a
walkthrough of a couple simple example apps.

Examples of using Bonsai in a web browser can be found in the `examples`
directory.

## Docs

Documentation can be found in the [docs](./docs) directory, and API documentation
can be found in [src/bonsai.mli](./src/bonsai.mli).
84 changes: 60 additions & 24 deletions bindings/dygraph/src/default_legend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Model = struct
module Series = struct
type t =
{ label : string
; override_label_for_visibility : string option
; value : Raw_html.t option
; dash : Raw_html.t option
; color : string option
Expand All @@ -15,7 +16,21 @@ module Model = struct

let toggle_visibility t = { t with is_visible = not t.is_visible }

let view { label; value; dash; color; is_visible; is_highlighted } ~on_toggle =
let label_for_visibility t =
Option.value t.override_label_for_visibility ~default:t.label
;;

let view
{ label
; override_label_for_visibility = _
; value
; dash
; color
; is_visible
; is_highlighted
}
~on_toggle
=
let dash =
match dash with
| None -> Vdom.Node.none
Expand Down Expand Up @@ -64,12 +79,12 @@ module Model = struct
{ x_label : string
; x_value : Raw_html.t option
; series : Series.t list
; past_series : Series.t Map.M(String).t
; past_series_visibility : bool Map.M(String).t
}
[@@deriving equal, sexp]

let view
{ x_label; x_value; series; past_series = _ }
{ x_label; x_value; series; past_series_visibility = _ }
~on_toggle
~select_all
~select_none
Expand Down Expand Up @@ -109,7 +124,8 @@ module Model = struct
select_all_or_none
:: x
:: List.map series ~f:(fun series ->
Series.view series ~on_toggle:(fun () -> on_toggle series.label))
Series.view series ~on_toggle:(fun () ->
on_toggle (Series.label_for_visibility series)))
in
(* Mostly copied from vdom_input_widgets *)
Vdom.Node.div
Expand All @@ -127,7 +143,7 @@ end
module Action = struct
type t =
| From_graph of Legend_data.t
| Toggle_visibility of string
| Toggle_visibility of { label_for_visibility : string }
| Select_none
| Select_all
[@@deriving equal, sexp]
Expand Down Expand Up @@ -179,15 +195,18 @@ let apply_action
{ model with x_value; series }
| Select_none -> map_series ~f:(fun series -> { series with is_visible = false })
| Select_all -> map_series ~f:(fun series -> { series with is_visible = true })
| Toggle_visibility label ->
| Toggle_visibility { label_for_visibility } ->
map_series ~f:(fun series ->
if String.(series.label = label)
if String.(Model.Series.label_for_visibility series = label_for_visibility)
then Model.Series.toggle_visibility series
else series)
;;

let series_from_info { Per_series_info.label; visible_by_default } =
let series_from_info
{ Per_series_info.label; override_label_for_visibility; visible_by_default }
=
{ Model.Series.label
; override_label_for_visibility
; is_visible = visible_by_default
; is_highlighted = false
; value = None
Expand All @@ -207,7 +226,7 @@ let create ~x_label ~per_series_info
{ Model.x_label
; x_value = None
; series = List.map per_series_info ~f:series_from_info
; past_series = String.Map.empty
; past_series_visibility = String.Map.empty
}
| Some (model : Model.t) ->
let existing_y_labels = List.map model.series ~f:Model.Series.label in
Expand All @@ -216,24 +235,40 @@ let create ~x_label ~per_series_info
&& [%equal: string list] model_y_labels existing_y_labels
then { model with x_label }
else (
let past_series =
(* Every time the [model_y_labels] changes, we want to remember the visibility
status of all the series labels we know about so far. This will help in the
case where we toggle visibility on series A, flip to a graph which does not
have that series, and then flip back to the original graph. Without
remembering, the visibility status of series A revert back to the default
status. *)
List.fold ~init:model.past_series model.series ~f:(fun past_series series ->
Map.set past_series ~key:series.label ~data:series)
(* Every time the [model_y_labels] changes, we want to remember the visibility
status of all the series labels we know about so far. This will help in the
case where we toggle visibility on series A, flip to a graph which does not
have that series, and then flip back to the original graph. Without
remembering, the visibility status of series A revert back to the default
status. *)
let past_series_visibility =
List.fold
~init:model.past_series_visibility
model.series
~f:(fun past_series_visibility series ->
Map.set
past_series_visibility
~key:(Model.Series.label_for_visibility series)
~data:series.is_visible)
in
let series =
List.map per_series_info ~f:(fun per_series_info ->
let { Per_series_info.label; visible_by_default = _ } = per_series_info in
match Map.find past_series label with
| None -> series_from_info per_series_info
| Some series -> series)
let { Per_series_info.label
; override_label_for_visibility
; visible_by_default = _
}
=
per_series_info
in
let series = series_from_info per_series_info in
let label_for_visibility =
Option.value override_label_for_visibility ~default:label
in
match Map.find past_series_visibility label_for_visibility with
| None -> series
| Some is_visible -> { series with is_visible })
in
{ model with x_label; series; past_series })
{ model with x_label; series; past_series_visibility })
in
let%sub state =
Bonsai_extra.state_machine0_dynamic_model
Expand All @@ -250,7 +285,8 @@ let create ~x_label ~per_series_info
let view =
Model.view
model
~on_toggle:(fun label -> inject_action (Toggle_visibility label))
~on_toggle:(fun label_for_visibility ->
inject_action (Toggle_visibility { label_for_visibility }))
~select_all:(fun () -> inject_action Select_all)
~select_none:(fun () -> inject_action Select_none)
in
Expand Down
15 changes: 9 additions & 6 deletions bindings/dygraph/src/default_legend.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ module Model : sig
module Series : sig
type t =
{ label : string
; override_label_for_visibility : string option
; value : Raw_html.t option
; dash : Raw_html.t option
; color : string option
; is_visible : bool
; is_highlighted : bool
}
[@@deriving equal, fields ~getters, sexp]

val label_for_visibility : t -> string
end

type t =
{ x_label : string
; x_value : Raw_html.t option
; series : Series.t list
; past_series : Series.t Map.M(String).t
(** [past_series] remembers all the series (by series label) that we've ever seen.
This means that if someone makes a change to a particular series (e.g. toggles
visibility), moves to a graph without that series, and then moves back to the
original graph, the information will not be lost.
; past_series_visibility : bool Map.M(String).t
(** [past_series_visibility] remembers all the series (by [label_for_visibility]) that
we've ever seen. This means that if someone makes a change to a particular series
(e.g. toggles visibility), moves to a graph without that series, and then moves
back to the original graph, the information will not be lost.
This may sound like a memory leak, and it kind of is, but the hope is that the
total number of unique series labels that one sees over the lifetime of a graph is
Expand All @@ -42,7 +45,7 @@ end
module Action : sig
type t =
| From_graph of Legend_data.t
| Toggle_visibility of string
| Toggle_visibility of { label_for_visibility : string }
| Select_none
| Select_all
[@@deriving equal, sexp]
Expand Down
8 changes: 7 additions & 1 deletion bindings/dygraph/src/per_series_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ open! Import

type t =
{ label : string
; override_label_for_visibility : string option
; visible_by_default : bool
}
[@@deriving fields ~getters]

let create ?override_label_for_visibility label ~visible_by_default =
{ label; override_label_for_visibility; visible_by_default }
;;

let create_all_visible labels =
List.map labels ~f:(fun label -> { label; visible_by_default = true })
List.map labels ~f:(fun label ->
{ label; override_label_for_visibility = None; visible_by_default = true })
;;
17 changes: 17 additions & 0 deletions bindings/dygraph/src/per_series_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ open! Import

type t =
{ label : string
; override_label_for_visibility : string option
(** It may be helpful to distinguish the series label from the "label for visibility".
For example, in some graphs we encode information about the symbol we are looking at
in the series label. That information changes as you look at different symbols.
However, the second series always semantically means the same thing as you move from
symbol to symbol. If you uncheck the second series to disable visibility, you may
want to remember that change even if the series label changes.
If you want to just use the [label] as the semantic identifier for persisting
visilibity, then just set [override_label_for_visibility] to None. *)
; visible_by_default : bool
}
[@@deriving fields ~getters]

val create
: ?override_label_for_visibility:string
-> string
-> visible_by_default:bool
-> t

val create_all_visible : string list -> t list
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ degree than otherwise available.

## 2020-06-10
`Bonsai.Proc` module added. To read more, check out
[this document](./docs/blogs/proc.md).
[this document](./docs/blog/proc.md).

## 2020-03-17
- Model type removed from `('input, 'model, 'result) Bonsai.t`.
Expand Down
Loading

0 comments on commit d5d79a9

Please sign in to comment.