Skip to content

Commit 1a75214

Browse files
Merge pull request #32 from BigThinkcode/stroke_opacity
Cosmetics
2 parents f8873f8 + 8cf43fb commit 1a75214

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

lib/matplotex/element/rad_legend.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule Matplotex.Element.RadLegend do
22
@moduledoc false
3+
alias Matplotex.Utils.Algebra
34
alias Matplotex.Element.Label
45
alias Matplotex.Element
56
alias Matplotex.Element.Rect
@@ -10,6 +11,9 @@ defmodule Matplotex.Element.RadLegend do
1011
@stroke "rgba(0,0,0,0)"
1112
@legend_size 20 / 96
1213
@label_type "legend.label"
14+
@default_opacity 1.0
15+
16+
@legend_padding 5/96
1317
defstruct [
1418
:type,
1519
:x,
@@ -20,6 +24,8 @@ defmodule Matplotex.Element.RadLegend do
2024
height: @legend_size,
2125
label_margin: @legend_size,
2226
stroke: @stroke,
27+
stroke_opacity: @default_opacity,
28+
fill_opacity: @default_opacity,
2329
stroke_width: @stroke_width
2430
]
2531

@@ -41,12 +47,13 @@ defmodule Matplotex.Element.RadLegend do
4147
} = legend,
4248
legend_font
4349
) do
50+
{label_x, label_y} = Algebra.transform_given_point(x, y, width + @legend_padding, height/2)
4451
%{
4552
legend
4653
| label:
4754
%Label{
48-
x: x + width,
49-
y: y + height / 2,
55+
x: label_x,
56+
y: label_y,
5057
text: text,
5158
type: @label_type
5259
}

lib/matplotex/figure/radial/pie.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule Matplotex.Figure.Radial.Pie do
1616
use Radial
1717

1818
@full_circle 2 * :math.pi()
19+
@legend_padding 5/96
1920
chord(
2021
center: %TwoD{},
2122
lead: %TwoD{},
@@ -68,7 +69,7 @@ defmodule Matplotex.Figure.Radial.Pie do
6869
when fwidth > 0 and fheight > 0 do
6970
%Region{x: legx, y: legy} = Algebra.flip_y_coordinate(region_legend)
7071
total_size = Enum.sum(sizes)
71-
legend_rect_side = height / length(sizes) / 2
72+
legend_rect_side = height / length(sizes) / 4
7273
center = Algebra.flip_y_coordinate(center)
7374

7475
slices =
@@ -143,7 +144,7 @@ defmodule Matplotex.Figure.Radial.Pie do
143144
}
144145

145146
{x_legend, y_legend} =
146-
Algebra.transform_given_point(0, legend_unit_height, x_legend, y_legend)
147+
Algebra.transform_given_point(0, legend_unit_height + @legend_padding, x_legend, y_legend)
147148

148149
legend =
149150
%RadLegend{

lib/matplotex/helpers.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ defmodule Matplotex.Helpers do
258258

259259
def pie() do
260260
# Percentages for each slice
261-
sizes = [25, 35, 20, 20]
261+
sizes = [25, 35, 20, 20, 10]
262262
# Labels for each slice
263-
labels = ["A", "B", "C", "D"]
263+
labels = ["A", "B", "C", "D", "E"]
264264
# Colors for the slices
265-
colors = ["lightblue", "lightgreen", "orange", "pink"]
265+
colors = ["#33BBEE", "#EE7733", "#EE3377", "#0077BB","#919D41"]
266266

267267
sizes
268268
|> Matplotex.pie(colors: colors, labels: labels)
@@ -311,7 +311,7 @@ defmodule Matplotex.Helpers do
311311

312312
def hist() do
313313
values = Nx.Random.key(12) |> Nx.Random.normal(0, 1, shape: {1000}) |> elem(0) |> Nx.to_list()
314-
bins = 30
314+
bins = 100
315315

316316
Matplotex.hist(values, bins,
317317
x_label: "Value",

0 commit comments

Comments
 (0)