Skip to content

Commit af00675

Browse files
Merge pull request #51 from BigThinkcode/release_stacked_bar
doc update
2 parents c1864e2 + a1f1079 commit af00675

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The package can be installed by adding <font color="darkblue"> **Matplotex**</fo
3939
```elixir
4040
def deps do
4141
[
42-
{:matplotex, "~> 0.4.71" }
42+
{:matplotex, "~> 0.4.8" }
4343
]
4444
```
4545

lib/matplotex.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,23 @@ defmodule Matplotex do
190190
```elixir
191191
192192
alias Matplotex as: M
193-
categories = ["apple", "banana", "fig", "avocado"]
193+
categories = ["lorem", "ipsum", "amet", "adore"]
194194
values1 = [22, 33, 28, 34]
195195
iex> Matplotex.bar(width, values1, width, label: "Dataset1", color: "#255199")
196196
%M.Figure{axes: %M.Figure.Areal.BarChart{...}, ...}
197197
```
198198
199+
- To draw a stacked bar chart
200+
```elixir
201+
categories = ["lorem", "ipsum", "amet", "adore"]
202+
values1 = [22, 33, 28, 34]
203+
values2 = [12, 23, 18, 24]
204+
values3 = [22, 33, 28, 34]
205+
iex> Matplotex.bar(width, values1, width, label: "Dataset1", color: "#255199")
206+
|> Matplotex.bar(width, values2, width, label: "Dataset2", color: "blue", bottom: values1)
207+
|> Matplotex.bar(width, values3, width, label: "Dataset3", color: "green", bottom: [values1, values2])x
208+
```
209+
199210
This function takes a list of numerical `values` and a single `width` value to create a bar chart where:
200211
- The height of each bar corresponds to its respective value from the list.
201212
- Each bar has the specified constant width.

lib/matplotex/figure/areal.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule Matplotex.Figure.Areal do
22
@moduledoc false
3+
alias Matplotex.InputError
34
alias Matplotex.Figure.Areal.Ticker
45
alias Matplotex.Utils.Algebra
56
alias Matplotex.Figure.Dataset
@@ -173,7 +174,7 @@ defmodule Matplotex.Figure.Areal do
173174
# For stacked bar chart the flattening supposed to be the sumation of yaxis data
174175
def flatten_for_data(datasets, nil), do: flatten_for_data(datasets)
175176

176-
def flatten_for_data([%{x: x, y: y} | _datasets], bottom) do
177+
def flatten_for_data([%{x: x, y: y} | _datasets], bottom) when is_list(bottom) do
177178
y =
178179
bottom
179180
|> Kernel.++([y])
@@ -183,6 +184,9 @@ defmodule Matplotex.Figure.Areal do
183184

184185
{x, y}
185186
end
187+
def flatten_for_data(_, _bottom) do
188+
raise InputError, bottom: "Wrong data provided for opts bottom"
189+
end
186190

187191
def flatten_for_data(datasets) do
188192
datasets

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Matplotex.MixProject do
55
[
66
app: :matplotex,
77
organization: :bigthinkcode,
8-
version: "0.4.71",
8+
version: "0.4.8",
99
elixir: "~> 1.17",
1010
start_permanent: Mix.env() == :prod,
1111
elixirc_paths: elixirc_paths(Mix.env()),

0 commit comments

Comments
 (0)