diff --git a/README.md b/README.md index 77a978f..7fe7ea6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The package can be installed by adding **Matplotex** 0.4.71" } + {:matplotex, "~> 0.4.8" } ] ``` diff --git a/lib/matplotex.ex b/lib/matplotex.ex index 0f7c402..5cd6d7d 100644 --- a/lib/matplotex.ex +++ b/lib/matplotex.ex @@ -190,12 +190,23 @@ defmodule Matplotex do ```elixir alias Matplotex as: M - categories = ["apple", "banana", "fig", "avocado"] + categories = ["lorem", "ipsum", "amet", "adore"] values1 = [22, 33, 28, 34] iex> Matplotex.bar(width, values1, width, label: "Dataset1", color: "#255199") %M.Figure{axes: %M.Figure.Areal.BarChart{...}, ...} ``` + - To draw a stacked bar chart + ```elixir + categories = ["lorem", "ipsum", "amet", "adore"] + values1 = [22, 33, 28, 34] + values2 = [12, 23, 18, 24] + values3 = [22, 33, 28, 34] + iex> Matplotex.bar(width, values1, width, label: "Dataset1", color: "#255199") + |> Matplotex.bar(width, values2, width, label: "Dataset2", color: "blue", bottom: values1) + |> Matplotex.bar(width, values3, width, label: "Dataset3", color: "green", bottom: [values1, values2])x + ``` + This function takes a list of numerical `values` and a single `width` value to create a bar chart where: - The height of each bar corresponds to its respective value from the list. - Each bar has the specified constant width. diff --git a/lib/matplotex/figure/areal.ex b/lib/matplotex/figure/areal.ex index 9c23061..7cce7d4 100644 --- a/lib/matplotex/figure/areal.ex +++ b/lib/matplotex/figure/areal.ex @@ -1,5 +1,6 @@ defmodule Matplotex.Figure.Areal do @moduledoc false + alias Matplotex.InputError alias Matplotex.Figure.Areal.Ticker alias Matplotex.Utils.Algebra alias Matplotex.Figure.Dataset @@ -173,7 +174,7 @@ defmodule Matplotex.Figure.Areal do # For stacked bar chart the flattening supposed to be the sumation of yaxis data def flatten_for_data(datasets, nil), do: flatten_for_data(datasets) - def flatten_for_data([%{x: x, y: y} | _datasets], bottom) do + def flatten_for_data([%{x: x, y: y} | _datasets], bottom) when is_list(bottom) do y = bottom |> Kernel.++([y]) @@ -183,6 +184,9 @@ defmodule Matplotex.Figure.Areal do {x, y} end + def flatten_for_data(_, _bottom) do + raise InputError, bottom: "Wrong data provided for opts bottom" + end def flatten_for_data(datasets) do datasets diff --git a/mix.exs b/mix.exs index 828f625..8f30b48 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Matplotex.MixProject do [ app: :matplotex, organization: :bigthinkcode, - version: "0.4.71", + version: "0.4.8", elixir: "~> 1.17", start_permanent: Mix.env() == :prod, elixirc_paths: elixirc_paths(Mix.env()),