You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/matplotex.ex
+38-43Lines changed: 38 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -2,25 +2,19 @@ defmodule Matplotex do
2
2
@moduledoc"""
3
3
# Matplotex
4
4
5
-
a lightweight and efficient library for Elixir projects that facilitates server-side
6
-
SVG generation for data visualization. Designed to integrate seamlessly with Phoenix LiveView,
7
-
it serves as a powerful tool for creating dynamic visualizations in web applications.
8
-
9
-
it supports the following graphs
10
-
- Line plots
11
-
- Bar charts
12
-
- Pie charts
13
-
- Spline graphs
14
-
- Histograms
15
-
- Scatter plots
16
-
17
-
The plotting of a graph comes with set of common parameters and set of plot specific parameters
18
-
all of them will share with the corresponding function documentation, this section covers one examaple
19
-
as a line plot.
20
-
There are two approach to generate plots
21
-
- by using specific function to set parameters
22
-
- by using parameters along with options
5
+
A lightweight and efficient Elixir library designed for server-side SVG generation, ideal for data visualization in web applications. It integrates seamlessly with Phoenix LiveView and provides powerful tools for generating dynamic visualizations.
23
6
7
+
## Supported Graph Types
8
+
9
+
Matplotex supports the following types of visualizations:
10
+
11
+
- Line Plots
12
+
- Bar Charts
13
+
- Pie Charts
14
+
- Spline Graphs
15
+
- Histograms
16
+
- Scatter Plots
17
+
## Examples
24
18
```elixir
25
19
alias Matplotex as: M
26
20
@@ -55,8 +49,7 @@ defmodule Matplotex do
55
49
)
56
50
|> M.show()
57
51
```
58
-
This module exposes all of the functions for setters
59
-
and another approach is creating plots by using plot options the code is as follows
52
+
60
53
```elixir
61
54
alis Matplotex as: M
62
55
x = [1, 2, 3, 4, 6, 6, 7]
@@ -90,37 +83,39 @@ defmodule Matplotex do
90
83
)
91
84
|> M.show()
92
85
```
93
-
just for simplicity and convenience of the user it is keeping both patterns, no difference on using one on another
86
+
**Note**: Both approaches are equivalent, and users can choose whichever pattern is more convenient.
87
+
88
+
89
+
## Runtime Configuration (RC Params)
90
+
The function M.set_rc_params/2 allows you to set runtime configuration parameters for the plot, such as font sizes, colors, and line styles. These settings affect visual elements like the font style and size for the labels, ticks, and title.
94
91
95
-
So the user has the control on the all parameters on the inner elements of the chart
92
+
By default, the plot starts with standard values (e.g., Arial or Verdana font, size 12). You can modify these using the RC parameters.
93
+
94
+
### Available RC Params:
95
+
line_width, line_style
96
+
grid_color, grid_linestyle, grid_alpha
97
+
tick_line_length
98
+
x_padding, y_padding, padding
99
+
legend_width
100
+
Refer to specific plot documentation for detailed information on padding usage.
96
101
97
-
## Rc Params
98
-
In the first example along with the setter functions you might noticed M.set_rc_params/2
99
-
The role of this function is similar to other functions we are keeping some values with the plot data
100
-
and the acronym RC stands for Runtime configuration, the plot data holds the labels limits ticks, etc
101
-
The RC params are holding the font size, color, style etc, by defaul one chart object kickstart with some default values
102
-
just for the sake of it needed some values, by default all the fonts are Areal, Veradana, sans-serif and using standard font size 12
103
-
if a user creates a plots with no inputs for any of these the plot will be choosing the default values
There is two types of padding `x_padding, y_padding` and `padding` the perfect use of those can be found on upcoming plot specific documentations
107
102
108
103
## Elements
109
104
The output format of the plot is SVG will support more formats in future, anyway the svg is a group of some elements put together, throught the execution
110
105
it is generating those elements through elixir data structure, all element data structure contains some svg equivalent data that converts the elements to
111
106
SVG string, the output SVG string can be used directly in the web application.
112
107
113
-
## Figure
114
-
The execution a plot carriec out by a data structure named Matplotex.Figure it holds all the adequate information to generate a figure it containst the keys
115
-
`:figsize` - is a tuple carries width and height of the figure eg: {10,6}
116
-
`:axes` - is another object that will varie according to the plot
117
-
`:rc_params` - the runtime configurations
118
-
`:margin` - the margin of the figure
119
-
120
-
## M.show/1
121
-
All examples above using this function `M.show/1` after a plot generation API call
122
-
The all APIs from this module is ment to return an svg equivalent Data Matplotex.Figure with distinct object associated with the `axes` key, so to convert that data to
123
-
an SVG chart use `M.show/1`
108
+
## Figure Data Structure
109
+
The main data structure used to generate a plot is Matplotex.Figure, which contains all the necessary information for the plot, including:
110
+
111
+
- `:figsize`: A tuple specifying the width and height of the figure (e.g., {10, 6}).
112
+
- `:axes`: Contains the axes data, which varies depending on the plot type.
113
+
- `:rc_params`: The runtime configuration parameters.
114
+
- `:margin`: Specifies the margin of the figure.
115
+
116
+
## `M.show/1`
117
+
After creating a figure using the functions provided, call M.show/1 to generate and display the final SVG representation of the plot. The show/1 function will convert the Matplotex.Figure data into a valid SVG string.
0 commit comments