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
26 changes: 22 additions & 4 deletions lib/matplotex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ defmodule Matplotex do
end

def bar(%Figure{} = figure, pos, values, width, opts) do
BarChart.create(figure, {pos, values, width}, opts)
figure
|> show_legend()
|> BarChart.create({pos, values, width}, opts)
end

def scatter(stream, opts) when is_struct(stream, Stream) do
Expand All @@ -35,7 +37,9 @@ defmodule Matplotex do
end

def scatter(%Figure{} = figure, x, y, opts) do
Scatter.create(figure, {x, y}, opts)
figure
|> show_legend()
|> Scatter.create({x, y}, opts)
end

def pie(sizes, opts \\ []) do
Expand Down Expand Up @@ -66,7 +70,9 @@ defmodule Matplotex do
end

def plot(%Figure{} = figure, x, y, opts) do
LinePlot.create(figure, {x, y}, opts)
figure
|> show_legend()
|> LinePlot.create({x, y}, opts)
end

@doc """
Expand Down Expand Up @@ -211,15 +217,27 @@ defmodule Matplotex do
iex> Matplotex.figure(figure, figsize: {10,6}, margin: 0.1)
%Matplotex.Figure{}
"""

@deprecated
def figure(figure, params) do
Figure.update_figure(figure, params)
end

def set_figure_size(figure, size) do
Figure.set_figure_size(figure, size)
end

def set_margin(figure, margin) do
Figure.set_margin(figure, margin)
end

def hide_v_grid(figure) do
Figure.hide_v_grid(figure)
end

def show_legend(figure) do
Figure.show_legend(figure)
end

@doc """
Function to update rc params, rc stands for runtime configuration
## Examples
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotex/blueprint/chord.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ defmodule Matplotex.Blueprint.Chord do
show_title: @true_by_default,
element: [],
legend_pos: nil,
border: nil
border: nil,
show_legend: @false_by_default
]
|> Keyword.merge(opts)
)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotex/blueprint/frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ defmodule Matplotex.Blueprint.Frame do
errors: [],
element: [],
show_title: false,
show_legend: false,
valid: @valid_by_default,
margin: @default_margin,
show_x_axis: @show_by_default,
Expand Down
17 changes: 16 additions & 1 deletion lib/matplotex/element/slice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@ defmodule Matplotex.Element.Slice do
alias Matplotex.Element
use Element

defstruct [:type, :x1, :y1, :x2, :y2, :cx, :cy, :data,:percentage, :radius, :color, :label, :legend]
defstruct [
:type,
:x1,
:y1,
:x2,
:y2,
:cx,
:cy,
:data,
:percentage,
:radius,
:color,
:label,
:legend
]

# TODO: change the fucntion name assemble to to_svg

@impl Element
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotex/figure.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ defmodule Matplotex.Figure do
def hide_v_grid(%__MODULE__{axes: %module{} = axes} = figure),
do: %{figure | axes: module.hide_v_grid(axes)}

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

def set_figure_size(%__MODULE__{margin: margin, axes: axes} = figure, {fwidth, fheight} = fsize) do
frame_size = {fwidth - fwidth * 2 * margin, fheight - fheight * 2 * margin}

%{figure | figsize: fsize, axes: %{axes | size: frame_size}}
end

def set_margin(%__MODULE__{figsize: {fwidth, fheight}, axes: axes} = figure, margin) do
frame_size = {fwidth - fwidth * 2 * margin, fheight - fheight * 2 * margin}
%__MODULE__{figure | margin: margin, axes: %{axes | size: frame_size}}
end

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

def update_figure(figure, params) do
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotex/figure/areal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ defmodule Matplotex.Figure.Areal do
def min_max(ticks) do
Enum.min_max(ticks)
end

def show_legend(%__MODULE__{} = axes) do
%__MODULE__{axes | show_legend: true}
end

def set_frame_size(%__MODULE__{} = axes, frame_size) do
%__MODULE__{axes | size: frame_size}
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/matplotex/figure/areal/bar_chart.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
defmodule Matplotex.Figure.Areal.BarChart do
import Matplotex.Figure.Numer
alias Matplotex.Figure.Region
alias Matplotex.Figure.Areal.Region
alias Matplotex.Figure.Dataset
alias Matplotex.Element.Rect
alias Matplotex.Figure.RcParams
alias Matplotex.Figure.Coords
alias Matplotex.Figure
alias Matplotex.Figure.Areal
use Areal

frame(
legend: %Legend{},
coords: %Coords{},
Expand Down
8 changes: 6 additions & 2 deletions 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
alias Matplotex.Figure.Region
alias Matplotex.Figure.Areal.Region
alias Matplotex.Figure.Areal.Ticker
alias Matplotex.Figure.Marker
alias Matplotex.Figure.Dataset
Expand Down Expand Up @@ -27,7 +27,11 @@ defmodule Matplotex.Figure.Areal.LinePlot do

@marker_size 3.5
@impl Areal
def create(%Figure{axes: %__MODULE__{dataset: data} = axes} = figure, {x, y}, opts \\ []) do
def create(
%Figure{axes: %__MODULE__{dataset: data} = axes} = figure,
{x, y},
opts \\ []
) do
x = determine_numeric_value(x)
y = determine_numeric_value(y)
dataset = Dataset.cast(%Dataset{x: x, y: y}, opts)
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotex/figure/areal/region.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Matplotex.Figure.Areal.Region do
defstruct [:x, :y, :width, :height, :name, :theta, :coords]
end
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
alias Matplotex.Figure.Region
alias Matplotex.Figure.Areal.Region
alias Matplotex.Figure.Areal.Ticker
alias Matplotex.Figure.Marker
alias Matplotex.Figure.Dataset
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotex/figure/areal/xy_region/coords.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Matplotex.Figure.Areal.XyRegion.Coords do
defstruct [:label, :ticks]
end
8 changes: 7 additions & 1 deletion lib/matplotex/figure/font.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ defmodule Matplotex.Figure.Font do
@default_font_size 16
@default_font_weight "normal"
@font_unit "pt"
@pt_to_inch_ratio 1 / 72
@text_rotation 0
@flate 0

defstruct font_size: @default_font_size,
font_style: @default_font_style,
font_family: @default_font_family,
font_weight: @default_font_weight,
fill: @default_font_color,
unit_of_measurement: @font_unit
unit_of_measurement: @font_unit,
pt_to_inch_ratio: @pt_to_inch_ratio,
rotation: @text_rotation,
flate: @flate

def font_keys() do
Map.keys(%__MODULE__{}) -- [:__struct__]
Expand Down
Loading