Skip to content

Commit ee923db

Browse files
author
Mohammed Sadique
committed
making whole data
1 parent 3e6493c commit ee923db

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

lib/matplotex/figure/areal.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ defmodule Matplotex.Figure.Areal do
5858
end
5959

6060
def add_title(axes, title, opts) when is_binary(title) do
61-
# title = Text.create_text(title, opts)
6261
%{axes | title: title, show_title: true}
6362
end
6463

@@ -170,6 +169,17 @@ defmodule Matplotex.Figure.Areal do
170169
data_with_label(data)
171170
end
172171
end
172+
# For stacked bar chart the flattening supposed to be the sumation of yaxis data
173+
def flatten_for_data(datasets,_data, nil), do: flatten_for_data(datasets)
174+
def flatten_for_data(_datasets,%{x: x, y: y} = _data, bottom) do
175+
y = bottom
176+
|> Tuple.to_list()
177+
|> Kernel.++(y)
178+
|> Nx.tensor(names: [:x, :y])
179+
|> Nx.sum(axes: [:x])
180+
|> Nx.to_list()
181+
{x, y}
182+
end
173183

174184
def flatten_for_data(datasets) do
175185
datasets

lib/matplotex/figure/areal/bar_chart.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ defmodule Matplotex.Figure.Areal.BarChart do
3636
x = hypox(values)
3737
dataset = Dataset.cast(%Dataset{x: x, y: values, pos: pos, width: width}, opts)
3838
datasets = data ++ [dataset]
39-
xydata = flatten_for_data(datasets)
39+
bottom = Keyword.get(opts, :bottom)
40+
xydata = flatten_for_data(datasets,data, bottom)
4041

4142
%Figure{
4243
figure
@@ -55,7 +56,7 @@ defmodule Matplotex.Figure.Areal.BarChart do
5556
axes:
5657
%{
5758
dataset: datasets,
58-
data: data,
59+
data: {_x, y},
5960
limit: %{x: xlim, y: ylim},
6061
type: "stacked",
6162
region_content: %Region{

0 commit comments

Comments
 (0)