From f34cbb0e5ac7351f99956d39a4c2c3b32d0924ff Mon Sep 17 00:00:00 2001 From: Mathieu Kerjouan <107192656+kfmak@users.noreply.github.com> Date: Fri, 18 Nov 2022 08:08:36 +0000 Subject: [PATCH] Fix Plot default_style issue `default_style` attribute can now be modified using `Plot.attributes/2` and `Plot.new` functions. --- lib/chart/axis.ex | 2 +- lib/chart/plot.ex | 6 +++--- test/contex_plot_test.exs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/chart/axis.ex b/lib/chart/axis.ex index 615fff7..95d29d0 100644 --- a/lib/chart/axis.ex +++ b/lib/chart/axis.ex @@ -113,7 +113,7 @@ defmodule Contex.Axis do [ "|, + ~s| fill="none" text-anchor="#{get_text_anchor(axis)}">|, ~s||, get_svg_tickmarks(axis), "" diff --git a/lib/chart/plot.ex b/lib/chart/plot.ex index 7b355d4..ff47eff 100644 --- a/lib/chart/plot.ex +++ b/lib/chart/plot.ex @@ -151,12 +151,11 @@ defmodule Contex.Plot do plot_options = Map.merge( plot.plot_options, - Map.take(attributes_map, [:show_x_axis, :show_y_axis, :legend_setting]) + Map.take(attributes_map, [:show_x_axis, :show_y_axis, :legend_setting, :default_style]) ) - plot |> Map.merge( - Map.take(attributes_map, [:title, :subtitle, :x_label, :y_label, :width, :height]) + Map.take(attributes_map, [:title, :subtitle, :x_label, :y_label, :width, :height, :default_style]) ) |> Map.put(:plot_options, plot_options) |> calculate_margins() @@ -336,6 +335,7 @@ defmodule Contex.Plot do subtitle: Keyword.get(attrs, :subtitle), x_label: Keyword.get(attrs, :x_label), y_label: Keyword.get(attrs, :y_label), + default_style: Keyword.get(attrs, :default_style), plot_options: Enum.into(Keyword.take(attrs, [:show_x_axis, :show_y_axis, :legend_setting]), %{}) } diff --git a/test/contex_plot_test.exs b/test/contex_plot_test.exs index fb98d7b..82f5e26 100644 --- a/test/contex_plot_test.exs +++ b/test/contex_plot_test.exs @@ -306,7 +306,7 @@ defmodule ContexPlotTest do test "does not render styles if default turned off", %{plot: plot} do refute plot - |> struct(default_style: false) + |> Plot.attributes(default_style: false) |> Plot.to_svg() |> elem(1) |> IO.chardata_to_string()