Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotex/blueprint.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Blueprint do
@moduledoc false
@moduledoc false
@callback new(graph :: module(), params :: map()) :: any()
@callback set_content(graphset :: any()) :: any()
@callback add_elements(graphset :: any()) :: any()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/blueprint/chord.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Blueprint.Chord do
@moduledoc false
@moduledoc false
@true_by_default false
@false_by_default true
defmacro chord(opts \\ []) do
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/blueprint/frame.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Blueprint.Frame do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.Legend
@default_margin 0.05
@show_by_default true
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element do
@moduledoc false
@moduledoc false
@callback assemble(element :: struct()) :: String.t()
def assemble(%module{} = element), do: module.assemble(element)

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/circle.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Circle do
@moduledoc false
@moduledoc false
alias Matplotex.Element
use Element

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/label.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Label do
@moduledoc false
@moduledoc false
alias Matplotex.Element
use Element
@default_fill "black"
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/legend.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Legend do
@moduledoc false
@moduledoc false
alias Matplotex.Element.Label
alias Matplotex.Element

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/line.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Line do
@moduledoc false
@moduledoc false
alias Matplotex.Element
use Element

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/polygon.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Polygon do
@moduledoc false
@moduledoc false
alias Matplotex.Element
use Element
@default_fill "blue"
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotex/element/rad_legend.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.RadLegend do
@moduledoc false
@moduledoc false
alias Matplotex.Utils.Algebra
alias Matplotex.Element.Label
alias Matplotex.Element
Expand All @@ -13,7 +13,7 @@ defmodule Matplotex.Element.RadLegend do
@label_type "legend.label"
@default_opacity 1.0

@legend_padding 5/96
@legend_padding 5 / 96
defstruct [
:type,
:x,
Expand Down Expand Up @@ -47,7 +47,8 @@ defmodule Matplotex.Element.RadLegend do
} = legend,
legend_font
) do
{label_x, label_y} = Algebra.transform_given_point(x, y, width + @legend_padding, height/2)
{label_x, label_y} = Algebra.transform_given_point(x, y, width + @legend_padding, height / 2)

%{
legend
| label:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/rect.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Rect do
@moduledoc false
@moduledoc false
alias Matplotex.Element

@default_stroke_width 2
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/slice.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Slice do
@moduledoc false
@moduledoc false
alias Matplotex.Element
use Element

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/spline.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Spline do
@moduledoc false
@moduledoc false
alias Matplotex.Element
use Element
@default_stroke_width 2
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/stencil.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Stencil do
@moduledoc false
@moduledoc false
def line(line) do
~s(
<line
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/element/tick.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Element.Tick do
@moduledoc false
@moduledoc false
alias Matplotex.Element
alias Matplotex.Element.Line
alias Matplotex.Element.Label
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotex/figure.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.RcParams
@row_column_default 1
@margin_default 0.05
Expand Down Expand Up @@ -74,7 +74,8 @@ defmodule Matplotex.Figure do
%__MODULE__{figure | margin: margin, axes: %{axes | size: frame_size}}
end

def materialize(%__MODULE__{axes: %module{}} = figure), do: figure|> module.materialized_by_region()|>module.materialize()
def materialize(%__MODULE__{axes: %module{}} = figure),
do: figure |> module.materialized_by_region() |> module.materialize()

def update_figure(figure, params) do
if valid_params?(params) do
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotex/figure/areal.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.Areal.Ticker
alias Matplotex.Utils.Algebra
alias Matplotex.Figure.Dataset
Expand Down Expand Up @@ -360,5 +360,4 @@ defmodule Matplotex.Figure.Areal do

%Dataset{dataset | transformed: transformed}
end

end
4 changes: 2 additions & 2 deletions lib/matplotex/figure/areal/bar_chart.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.BarChart do
@moduledoc false
@moduledoc false
import Matplotex.Figure.Numer
alias Matplotex.Figure.Areal.PlotOptions
alias Matplotex.Figure.Areal.Region
Expand Down Expand Up @@ -48,7 +48,7 @@ defmodule Matplotex.Figure.Areal.BarChart do

@impl Areal
def materialize(figure) do
materialize_bars(figure)
materialize_bars(figure)
end

defp materialize_bars(
Expand Down
11 changes: 8 additions & 3 deletions lib/matplotex/figure/areal/histogram.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.Histogram do
@moduledoc false
@moduledoc false
alias Matplotex.Element.Rect
alias Matplotex.Figure.RcParams
alias Matplotex.Figure.Areal.PlotOptions
Expand Down Expand Up @@ -150,15 +150,20 @@ defmodule Matplotex.Figure.Areal.Histogram do
{bins_dist, hists}
end

defp sanitize(%Figure{axes: %__MODULE__{data: {x, y}, limit: %TwoD{x: xlim, y: ylim}} = axes} = figure) do
defp sanitize(
%Figure{axes: %__MODULE__{data: {x, y}, limit: %TwoD{x: xlim, y: ylim}} = axes} = figure
) do
{ymin, ymax} = Enum.min_max(y)
{xmin, xmax} = Enum.min_max(x)

%Figure{
figure
| axes: %__MODULE__{
axes
| limit: %TwoD{x: xlim || {floor(xmin), ceil(xmax)}, y: ylim || {floor(ymin), ceil(ymax)}}
| limit: %TwoD{
x: xlim || {floor(xmin), ceil(xmax)},
y: ylim || {floor(ymin), ceil(ymax)}
}
}
}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/areal/line_plot.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.LinePlot do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.Areal.PlotOptions
alias Matplotex.Utils.Algebra
alias Matplotex.Figure.Areal.Region
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/areal/plot_options.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.PlotOptions do
@moduledoc false
@moduledoc false
alias Matplotex.Figure
alias Matplotex.Figure.TwoD
alias Matplotex.Figure.RcParams
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/areal/region.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.Region do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.Areal.XyRegion.Coords
@zero_by_default 0
defstruct x: @zero_by_default,
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/areal/scatter.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.Scatter do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.Areal.PlotOptions
alias Matplotex.Figure.Areal.Region
alias Matplotex.Figure.Areal.Ticker
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotex/figure/areal/spline.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.Spline do
@moduledoc false
@moduledoc false
alias Matplotex.Element.Spline
alias Matplotex.Figure.RcParams
alias Matplotex.Figure.Areal
Expand Down Expand Up @@ -86,6 +86,7 @@ defmodule Matplotex.Figure.Areal.Spline do

%Figure{figure | axes: %{axes | element: elements}}
end

defp capture(
%Dataset{
transformed: transformed,
Expand All @@ -98,6 +99,7 @@ defmodule Matplotex.Figure.Areal.Spline do
{moveto, transformed} = List.pop_at(transformed, 0, move_to_def)
cubic = Enum.slice(transformed, 0..2)
smooths = blend(transformed, 3)

%Spline{
type: "figure.spline",
moveto: moveto,
Expand Down
57 changes: 30 additions & 27 deletions lib/matplotex/figure/areal/step.ex
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
defmodule Matplotex.Figure.Areal.Step do

alias Matplotex.Figure.Areal.LinePlot
alias Matplotex.Figure
alias Matplotex.InputError

def create(x, y, opts) do
{x, y} = step_segments(x, y)
LinePlot.create(%Figure{axes: %LinePlot{}}, {x, y}, opts)
end
def create(%Figure{} = figure, x, y, opts) do
{x, y} = step_segments(x, y)
LinePlot.create(figure, {x, y}, opts)
end
defp step_segments(x, y) do
x = horizontal_segments(x)
y = vertical_segments(y)
{x,y}
end
defp horizontal_segments(data) when is_list(data) do
first_value = List.first(data)
second_last_index = length(data) - 1
repeated = data|>Enum.slice(1..second_last_index)|>List.duplicate(2)|> List.flatten()
[first_value | repeated]|>Enum.sort()
end
defp horizontal_segments(_data), do: list_error(:y)

defp vertical_segments(data) when is_list(data) do
data|>List.duplicate(2)|>List.flatten()|>Enum.sort()
end
defp vertical_segments(_data), do: list_error(:y)

defp list_error(arg) do
raise InputError, message: "Expected a list for arg: #{arg}"
end
end

def create(%Figure{} = figure, x, y, opts) do
{x, y} = step_segments(x, y)
LinePlot.create(figure, {x, y}, opts)
end

defp step_segments(x, y) do
x = horizontal_segments(x)
y = vertical_segments(y)
{x, y}
end

defp horizontal_segments(data) when is_list(data) do
first_value = List.first(data)
second_last_index = length(data) - 1
repeated = data |> Enum.slice(1..second_last_index) |> List.duplicate(2) |> List.flatten()
[first_value | repeated] |> Enum.sort()
end

defp horizontal_segments(_data), do: list_error(:y)

defp vertical_segments(data) when is_list(data) do
data |> List.duplicate(2) |> List.flatten() |> Enum.sort()
end

defp vertical_segments(_data), do: list_error(:y)

defp list_error(arg) do
raise InputError, message: "Expected a list for arg: #{arg}"
end
end
2 changes: 1 addition & 1 deletion lib/matplotex/figure/areal/ticker.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Areal.Ticker do
@moduledoc false
@moduledoc false
@tick_in_plot 5
def generate_ticks({min, max}) do
step = (max - min) / @tick_in_plot
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/areal/xy_region/coords.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Matplotex.Figure.Areal.XyRegion.Coords do
@moduledoc false
@moduledoc false
defstruct [:label, :ticks, :grids]
end
10 changes: 4 additions & 6 deletions lib/matplotex/figure/cast.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Cast do
@moduledoc false
@moduledoc false
alias Matplotex.Figure.Lead
alias Matplotex.Element.Legend
alias Matplotex.Utils.Algebra
Expand All @@ -18,7 +18,6 @@ defmodule Matplotex.Figure.Cast do
@lowest_tick 0
@zero_to_move 0


def cast_spines_by_region(
%Figure{
axes:
Expand Down Expand Up @@ -128,14 +127,12 @@ defmodule Matplotex.Figure.Cast do
%Figure{figure | axes: %{axes | element: elements ++ [title]}}
end


def cast_label_by_region(figure) do
figure
|> cast_xlabel_by_region()
|> cast_ylabel_by_region()
end


def cast_xlabel_by_region(
%Figure{
axes: %{label: %{x: x_label}, region_x: region_x, element: element} = axes,
Expand Down Expand Up @@ -183,7 +180,9 @@ defmodule Matplotex.Figure.Cast do
element = element ++ [y_label]
%Figure{figure | axes: %{axes | element: element}}
end
def cast_ylabel_by_region(figure), do: figure

def cast_ylabel_by_region(figure), do: figure

def cast_xticks_by_region(
%Figure{
axes:
Expand Down Expand Up @@ -311,7 +310,6 @@ defmodule Matplotex.Figure.Cast do
}
} = figure
) do

y_ticks = confine_ticks(y_ticks, ylim)
y_data = confine_data(y_data, ylim)
dataset = confine_data(dataset, ylim, :y)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/coords.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Coords do
@moduledoc false
@moduledoc false
defstruct [
:title,
:x_label,
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotex/figure/dataset.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Matplotex.Figure.Dataset do
@moduledoc false
@moduledoc false
@default_color "blue"
@default_marker "o"
@default_linestyle "_"
Expand Down
Loading