From f471c7c9398631692a5a4bf2000b6aef0d26bf39 Mon Sep 17 00:00:00 2001 From: pnezis Date: Fri, 22 Dec 2023 14:12:01 +0200 Subject: [PATCH] rename groupby to group_by in density/3 --- CHANGELOG.md | 1 + lib/tucan.ex | 18 ++++++++++-------- test/tucan_test.exs | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67c3a32..660282f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Tucan.scatter(:iris, "petal_width", "petal_length") - Flipped `:orient` semantics for `Tucan.bar/4` - Rename `:group` option to `:group_by` in `Tucan.stripplot/3` for consistency. +- Rename `:groupby` option to `:group_by` in `Tucan.density/3` for consistency. ### Deprecated diff --git a/lib/tucan.ex b/lib/tucan.ex index e63c873..528bc6c 100644 --- a/lib/tucan.ex +++ b/lib/tucan.ex @@ -419,18 +419,18 @@ defmodule Tucan do doc: "Whether the density plot will be filled or not, default to `true` if not set", section: :style ], - groupby: [ + group_by: [ type: {:list, :string}, doc: """ The data fields to group by. If not specified, a single group containing all data objects will be used. This is applied only on the density transform. - In most cases you only need to set `color_by` which will automatically handle the - density transform grouping. Use `groupby` only if you want to manually post-process + In most cases you only need to set `:color_by` which will automatically handle the + density transform grouping. Use `:group_by` only if you want to manually post-process the generated specification, or if you want to apply grouping by more than one variable. - If both `groupby` and `color_by` are set then only `groupby` is used for grouping + If both `:group_by` and `:color_by` are set then only `:group_by` is used for grouping the density transform and `color_by` is used for encoding the color. """, dest: :density_transform @@ -541,11 +541,11 @@ defmodule Tucan do > Tucan.density(:penguins, "Body Mass (g)", color_by: "Species", fill_opacity: 0.2) > ``` > - > Alternatively you should use the `:groupby` option in order to group the density + > Alternatively you should use the `:group_by` option in order to group the density > transform by the `Species` field and then apply the `color_by/3` function: > > ```elixir - > Tucan.density(:penguins, "Body Mass (g)", groupby: ["Species"], fill_opacity: 0.2) + > Tucan.density(:penguins, "Body Mass (g)", group_by: ["Species"], fill_opacity: 0.2) > |> Tucan.color_by("Species") > ``` @@ -570,11 +570,11 @@ defmodule Tucan do ``` You can also combine it with `facet_by/4` in order to draw a different plot for each value - of the grouping variable. Notice that we need to set the `:groupby` variable in order + of the grouping variable. Notice that we need to set the `:group_by` variable in order to correctly calculate the density plot per field's value. ```tucan - Tucan.density(:penguins, "Body Mass (g)", groupby: ["Species"]) + Tucan.density(:penguins, "Body Mass (g)", group_by: ["Species"]) |> Tucan.color_by("Species") |> Tucan.facet_by(:column, "Species") ``` @@ -625,7 +625,9 @@ defmodule Tucan do transform_opts = Tucan.Options.take_options(opts, @density_opts, :density_transform) + |> Keyword.drop([:group_by]) |> Keyword.merge(density: field) + |> Tucan.Keyword.put_not_nil(:groupby, opts[:group_by]) |> Tucan.Keyword.put_new_conditionally(:groupby, [opts[:color_by]], fn -> opts[:color_by] != nil end) diff --git a/test/tucan_test.exs b/test/tucan_test.exs index 8ef4916..1949e36 100644 --- a/test/tucan_test.exs +++ b/test/tucan_test.exs @@ -905,7 +905,7 @@ defmodule TucanTest do minsteps: 5, maxsteps: 30, cumulative: true, - groupby: ["species"] + group_by: ["species"] ) == expected end @@ -956,7 +956,7 @@ defmodule TucanTest do ) |> Vl.encode_field(:color, "species") - assert Tucan.density(@iris_dataset, "petal_width", groupby: ["other"], color_by: "species") == + assert Tucan.density(@iris_dataset, "petal_width", group_by: ["other"], color_by: "species") == expected end end