Skip to content

Commit c95f892

Browse files
author
Mohammed Sadique
committed
scceed
1 parent d50d961 commit c95f892

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

lib/matplotex/figure/areal/bar_chart.ex

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,18 @@ defmodule Matplotex.Figure.Areal.BarChart do
242242
defp capture_stacked(to_capture, captured, dataset, bly) do
243243
to_capture
244244
|>Enum.map(fn point ->
245-
calculate_point(point, bly)
245+
format_point(point, bly)
246246
end)
247247
|>capture(captured, dataset)
248248
end
249249

250-
defp calculate_point({x, y}, _bly) when is_list(y) do
251-
{{x, Enum.sum(y)}, y|>tl()|>Enum.sum()}
252-
end
250+
defp format_point({{_x, _y}, _y_bottom} = point, _bly), do: point
251+
# sum_of_tail = y |> Enum.sort()|>tl()|>Enum.sum
252+
# sum_of_second_tail = y|>tl()|>tl()|>Enum.sum()
253+
# {{x, y|>Enum.max()|>Kernel.-(sum_of_tail)}, y|>tl()|>Enum.max()|> Kernel.-(sum_of_second_tail)}
254+
# end
253255

254-
defp calculate_point({x, y}, bly) do
256+
defp format_point({x, y}, bly) do
255257
{{x, y}, bly}
256258
end
257259
defp hypox(y) do
@@ -288,13 +290,16 @@ defmodule Matplotex.Figure.Areal.BarChart do
288290
end
289291

290292
defp transform_with_bottom(x, y, xlim, ylim, width, height, transition) when is_list(y) do
291-
transformed = Enum.map(y, fn y_with_bottom ->
292-
transformation(x, y_with_bottom, xlim, ylim, width, height, transition)
293-
|> Algebra.flip_y_coordinate()
294-
end)
295-
|>Enum.unzip()
296-
297-
{transformed|>elem(0)|>hd, transformed|> elem(1)}
293+
# transformed = Enum.map(y, fn y_with_bottom ->
294+
# transformation(x, y_with_bottom, xlim, ylim, width, height, transition)
295+
# |> Algebra.flip_y_coordinate()
296+
# end)
297+
# |>Enum.unzip()
298+
y_top = Enum.sum(y)
299+
y_bottom = y|>tl()|>Enum.sum()
300+
transformed = transformation(x, y_top, xlim, ylim, width, height, transition) |> Algebra.flip_y_coordinate()
301+
{_, transformed_y_bottom} = transformation(x, y_bottom, xlim, ylim, width, height,transition) |> Algebra.flip_y_coordinate()
302+
{transformed, transformed_y_bottom}
298303
end
299304

300305
defp transform_with_bottom(x, y, xlim, ylim, width, height, transition) do

test/matplotex/figure/areal/bar_chart_test.exs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ defmodule Matplotex.Figure.Areal.BarChartTest do
2828
|> Matplotex.bar(values3, width, bottom: [values2, values1])
2929
expected_elements_count = values1 ++ values2 ++ values3 |> length()
3030
assert %Figure{axes: %{element: elements}} = Figure.materialize(bar)
31-
32-
assert Enum.filter(elements, fn x -> x.type == "figure.bar" end) |> length() ==
33-
expected_elements_count
31+
bar_elements = Enum.filter(elements, fn x -> x.type == "figure.bar" end)
32+
assert bar_elements |> length() == expected_elements_count
33+
assert Enum.all?(bar_elements, fn rect -> assert_valid_coords(rect) end)
3434
end
3535
end
36+
defp assert_valid_coords(rect) do
37+
rect.x > 0 and rect.y > 0 and rect.width > 0 and rect.height > 0
38+
end
3639
end

0 commit comments

Comments
 (0)