Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed May 4, 2024
1 parent 4609e98 commit 0ab074b
Show file tree
Hide file tree
Showing 61 changed files with 457 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
always_for_in = true
for_in_replacement = ""
always_for_in = true
import_to_using = false
align_pair_arrow = true
align_assignment = true
Expand Down
60 changes: 30 additions & 30 deletions PlotsBase/ext/GRExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ function gr_polyline(x, y, func = GR.polyline; arrowside = :none, arrowstyle = :
iend = 0
while iend < n - 1
istart = -1 # set istart to the first index that is finite
for j in (iend + 1):n
for j (iend + 1):n
if ok(x[j], y[j])
istart = j
break
end
end
if istart > 0
iend = -1 # iend is the last finite index
for j in (istart + 1):n
for j (istart + 1):n
if ok(x[j], y[j])
iend = j
else
Expand Down Expand Up @@ -404,15 +404,15 @@ function gr_polyline3d(x, y, z, func = GR.polyline3d)
n = length(x)
while iend < n - 1
istart = -1 # set istart to the first index that is finite
for j in (iend + 1):n
for j (iend + 1):n
if ok(x[j], y[j], z[j])
istart = j
break
end
end
if istart > 0
iend = -1 # iend is the last finite index
for j in (istart + 1):n
for j (istart + 1):n
if ok(x[j], y[j], z[j])
iend = j
else
Expand Down Expand Up @@ -467,7 +467,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
sp,
)
gr_set_transparency(xaxis[:foreground_color_grid], xaxis[:gridalpha])
for i in eachindex(α)
for i eachindex(α)
GR.polyline([sinf[i], 0], [cosf[i], 0])
end
end
Expand All @@ -481,7 +481,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
sp,
)
gr_set_transparency(yaxis[:foreground_color_grid], yaxis[:gridalpha])
for i in eachindex(rtick_values)
for i eachindex(rtick_values)
r = (rtick_values[i] - rmin) / (rmax - rmin)
(r 1 && r 0) && GR.drawarc(-r, r, -r, r, 0, 359)
end
Expand All @@ -496,14 +496,14 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
# draw angular ticks
if xaxis[:showaxis]
GR.drawarc(-1, 1, -1, 1, 0, 359)
for i in eachindex(α)
for i eachindex(α)
x, y = GR.wctondc(1.1sinf[i], 1.1cosf[i])
GR.textext(x, y, string((360 - α[i]) % 360, "^o"))
end
end

# draw radial ticks
yaxis[:showaxis] && for i in eachindex(rtick_values)
yaxis[:showaxis] && for i eachindex(rtick_values)
r = (rtick_values[i] - rmin) / (rmax - rmin)
(r 1 && r 0) && gr_text(GR.wctondc(0.05, r)..., _cycle(rtick_labels, i))
end
Expand Down Expand Up @@ -706,7 +706,7 @@ end

function _cbar_unique(values, propname)
out = last(values)
if any(x != out for x in values)
if any(x != out for x values)
@warn """
Multiple series with different $propname share a colorbar.
Colorbar may not reflect all series correctly.
Expand Down Expand Up @@ -763,7 +763,7 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, vp::GRViewport)
push!(levels, z_max)
end
colors = gr_colorbar_colors(last(series), clims)
for (from, to, color) in zip(levels[1:(end - 1)], levels[2:end], colors)
for (from, to, color) zip(levels[1:(end - 1)], levels[2:end], colors)
GR.setfillcolorind(color)
GR.fillrect(x_min, x_max, from, to)
end
Expand All @@ -781,7 +781,7 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, vp::GRViewport)
gr_set_transparency(_cbar_unique(get_linealpha.(series), "line alpha"))
levels = _cbar_unique(contour_levels.(series, Ref(clims)), "levels")
colors = gr_colorbar_colors(last(series), clims)
for (line, color) in zip(levels, colors)
for (line, color) zip(levels, colors)
GR.setlinecolorind(color)
GR.polyline([x_min, x_max], [line, line])
end
Expand Down Expand Up @@ -825,7 +825,7 @@ alignment(symb) =

function gr_set_gradient(c)
grad = _as_gradient(c)
for (i, z) in enumerate(range(0, 1; length = 256))
for (i, z) enumerate(range(0, 1; length = 256))
c = grad[z]
GR.setcolorrep(999 + i, red(c), green(c), blue(c))
end
Expand Down Expand Up @@ -925,7 +925,7 @@ end

function gr_get_ticks_size(ticks, rot)
w, h = 0.0, 0.0
for (cv, dv) in zip(ticks...)
for (cv, dv) zip(ticks...)
wi, hi = gr_text_size(dv, rot)
w = NaNMath.max(w, wi)
h = NaNMath.max(h, hi)
Expand Down Expand Up @@ -996,7 +996,7 @@ function PlotsBase._update_min_padding!(sp::Subplot{GRBackend})
if gr_is3d(sp)
# Add margin for x and y ticks
m = 0mm
for (ax, tc) in ((xaxis, xticks), (yaxis, yticks))
for (ax, tc) ((xaxis, xticks), (yaxis, yticks))
isempty(first(tc)) && continue
rot = ax[:rotation]
gr_set_tickfont(
Expand Down Expand Up @@ -1027,7 +1027,7 @@ function PlotsBase._update_min_padding!(sp::Subplot{GRBackend})

# Add margin for x or y label
m = 0mm
for ax in (xaxis, yaxis)
for ax (xaxis, yaxis)
(guide = ax[:guide] == "") && continue
gr_set_font(guidefont(ax), sp)
l = last(gr_text_size(guide))
Expand All @@ -1045,7 +1045,7 @@ function PlotsBase._update_min_padding!(sp::Subplot{GRBackend})
end
else
# Add margin for x/y ticks & labels
for (ax, tc, (a, b)) in
for (ax, tc, (a, b))
((xaxis, xticks, (:top, :bottom)), (yaxis, yticks, (:right, :left)))
if !isempty(first(tc))
isy = ax[:letter] :y
Expand Down Expand Up @@ -1142,7 +1142,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, vp_canvas::GRViewport)
# init the colorbar
cbar = GRColorbar()

for series in series_list(sp)
for series series_list(sp)
gr_add_series(sp, series)
gr_update_colorbar!(cbar, series)
end
Expand All @@ -1154,7 +1154,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, vp_canvas::GRViewport)
gr_add_legend(sp, leg, vp_plt)

# add annotations
for ann in sp[:annotations]
for ann sp[:annotations]
x, y = if PlotsBase.is3d(sp)
x, y, z, val = locate_annotation(sp, ann...)
GR.setwindow(-1, 1, -1, 1)
Expand Down Expand Up @@ -1222,7 +1222,7 @@ function gr_add_legend(sp, leg, viewport_area)

nentry = 1

for series in series_list(sp)
for series series_list(sp)
should_add_to_legend(series) || continue
st = series[:seriestype]
clims = gr_clims(sp, series)
Expand Down Expand Up @@ -1395,7 +1395,7 @@ function gr_get_legend_geometry(vp, sp)
textw = r - l
end
gr_set_font(legendfont(sp), sp)
for series in series_list(sp)
for series series_list(sp)
should_add_to_legend(series) || continue
(l, r), (b, t) = extrema.(gr_inqtext(0, 0, string(series[:label])))
texth = max(texth, t - b)
Expand Down Expand Up @@ -1715,7 +1715,7 @@ function gr_label_ticks(sp, letter, ticks)
else
rot < -270 || -90 < rot < 90 || rot > 270 ? 1 : -1
end
for (cv, dv) in zip(ticks...)
for (cv, dv) zip(ticks...)
x, y = GR.wctondc(reverse_if((cv, ov), isy)...)
sz_rot, sz = gr_text_size(dv, rot), gr_text_size(dv)
x_off, y_off = x_offset, y_offset
Expand Down Expand Up @@ -1790,7 +1790,7 @@ function gr_label_ticks_3d(sp, letter, ticks)
end

GR.setwindow(-1, 1, -1, 1)
for (cv, dv) in zip((ax[:flip] ? reverse(cvs) : cvs, dvs)...)
for (cv, dv) zip((ax[:flip] ? reverse(cvs) : cvs, dvs)...)
xi, yi = gr_w3tondc(sort_3d_axes(cv, nt, ft, letter)...)
sz_rot, sz = gr_text_size(dv, rot), gr_text_size(dv)
x_off = x_offset + 0.5(sgn2a * first(sz_rot) + sgn3 * last(sz) * sind(rot))
Expand Down Expand Up @@ -1944,7 +1944,7 @@ function gr_add_series(sp, series)
end

# this is all we need to add the series_annotations text
for (xi, yi, str, fnt) in EachAnn(series[:series_annotations], x, y)
for (xi, yi, str, fnt) EachAnn(series[:series_annotations], x, y)
gr_set_font(fnt, sp)
gr_text(GR.wctondc(xi, yi)..., str)
end
Expand Down Expand Up @@ -1975,7 +1975,7 @@ function gr_draw_segments(series, x, y, z, fillrange, clims)

# draw the line(s)
st = series[:seriestype]
for segment in series_segments(series, st; check = true)
for segment series_segments(series, st; check = true)
i, rng = segment.attr_index, segment.range
isempty(rng) && continue
is3d = st :path3d && z nothing
Expand Down Expand Up @@ -2016,14 +2016,14 @@ function gr_draw_markers(
isempty(x) && return
GR.setfillintstyle(GR.INTSTYLE_SOLID)
(shapes = series[:markershape]) :none && return
for segment in series_segments(series, :scatter)
for segment series_segments(series, :scatter)
rng = intersect(eachindex(IndexLinear(), x), segment.range)
isempty(rng) && continue
i = segment.attr_index
ms = get_thickness_scaling(series) * _cycle(msize, i)
msw = get_thickness_scaling(series) * _cycle(strokewidth, i)
shape = _cycle(shapes, i)
for j in rng
for j rng
gr_draw_marker(
series,
_cycle(x, j),
Expand All @@ -2041,7 +2041,7 @@ end

function gr_draw_shapes(series, clims)
x, y = PlotsBase.shape_data(series)
for segment in series_segments(series, :shape)
for segment series_segments(series, :shape)
i, rng = segment.attr_index, segment.range
if length(rng) > 1
# connect to the beginning
Expand Down Expand Up @@ -2181,7 +2181,7 @@ function gr_draw_heatmap(series, x, y, z, clims)
z_log, z_normalized = gr_z_normalized_log_scaled(scale, z, clims)
z_log, plot_color.(map(z -> get(fillgrad, z), z_normalized), series[:fillalpha])
end
for i in eachindex(colors)
for i eachindex(colors)
isnan(_z[i]) && (colors[i] = set_RGBA_alpha(0, colors[i]))
end
GR.drawimage(first(x), last(x), last(y), first(y), w, h, gr_color.(colors))
Expand All @@ -2196,7 +2196,7 @@ function gr_draw_heatmap(series, x, y, z, clims)
end
rgba = map(x -> round(Int32, 1_000 + 255x), z_normalized)
bg_rgba = gr_getcolorind(plot_color(sp[:background_color_inside]))
for i in eachindex(rgba)
for i eachindex(rgba)
isnan(_z[i]) && (rgba[i] = bg_rgba)
end
if ispolar(series)
Expand All @@ -2221,7 +2221,7 @@ end

# ----------------------------------------------------------------

for (mime, fmt) in (
for (mime, fmt) (
"application/pdf" => "pdf",
"image/png" => "png",
"application/postscript" => "ps",
Expand Down
30 changes: 15 additions & 15 deletions PlotsBase/ext/GastonExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ function PlotsBase._before_layout_calcs(plt::Plot{GastonBackend})
# then add the series (curves in gaston)
foreach(series -> gaston_add_series(plt, series), plt.series_list)

for sp in plt.subplots
for sp plt.subplots
sp nothing && continue
for ann in sp[:annotations]
for ann sp[:annotations]
x, y, val = locate_annotation(sp, ann...)
sp.o.axesconf *= "; set label '$(val.str)' at $x,$y $(gaston_font(val.font))"
end
Expand All @@ -167,7 +167,7 @@ function PlotsBase._update_plot_object(plt::Plot{GastonBackend})
nothing
end

for (mime, term) in (
for (mime, term) (
"application/eps" => "epscairo",
"image/eps" => "epscairo",
"application/pdf" => "pdfcairo",
Expand Down Expand Up @@ -231,7 +231,7 @@ end
function gaston_get_subplots(n, plt_subplots, layout)
nr, nc = size(layout)
sps = Array{Any}(nothing, nr, nc)
for r in 1:nr, c in 1:nc # NOTE: col major
for r 1:nr, c 1:nc # NOTE: col major
sps[r, c] = if (l = layout[r, c]) isa GridLayout
n, sub = gaston_get_subplots(n, plt_subplots, l)
size(sub) == (1, 1) ? only(sub) : sub
Expand All @@ -249,7 +249,7 @@ end

function gaston_init_subplots(plt, sps)
sz = nr, nc = size(sps)
for c in 1:nc, r in 1:nr # NOTE: row major
for c 1:nc, r 1:nr # NOTE: row major
if (sp = sps[r, c]) isa Subplot || sp nothing
gaston_init_subplot(plt, sp)
else
Expand All @@ -270,7 +270,7 @@ function gaston_init_subplot(
dims =
RecipesPipeline.is3d(sp) || sp[:projection] == "3d" || needs_any_3d_axes(sp) ? 3 : 2
any_label = false
for series in series_list(sp)
for series series_list(sp)
if dims == 2 && series[:seriestype] (:heatmap, :contour)
dims = 3 # we need heatmap/contour to use splot, not plot
end
Expand All @@ -286,7 +286,7 @@ end
function gaston_multiplot_pos_size(layout, parent_xy_wh)
nr, nc = size(layout)
dat = Array{Any}(nothing, nr, nc)
for r in 1:nr, c in 1:nc
for r 1:nr, c 1:nc
l = layout[r, c]
# width and height (pct) are multiplicative (parent)
w = layout.widths[c].value * parent_xy_wh[3]
Expand Down Expand Up @@ -314,7 +314,7 @@ end

function gaston_multiplot_pos_size!(dat)
nr, nc = size(dat)
for r in 1:nr, c in 1:nc
for r 1:nr, c 1:nc
if (xy_wh_sp = dat[r, c]) isa Array
gaston_multiplot_pos_size!(xy_wh_sp)
elseif xy_wh_sp isa Tuple
Expand All @@ -336,10 +336,10 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
st = series[:seriestype]
curves = Gaston.Curve[]
if gsp.dims == 2 && z nothing
for (n, seg) in enumerate(series_segments(series, st; check = true))
for (n, seg) enumerate(series_segments(series, st; check = true))
i, rng = seg.attr_index, seg.range
fr = _cycle(series[:fillrange], 1:length(x[rng]))
for sc in gaston_seriesconf!(sp, series, n == 1, i)
for sc gaston_seriesconf!(sp, series, n == 1, i)
push!(curves, Gaston.Curve(x[rng], y[rng], nothing, fr, sc))
end
end
Expand Down Expand Up @@ -369,12 +369,12 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
z = reshape(z, length(y), length(x))
end
end
for sc in gaston_seriesconf!(sp, series, true, 1)
for sc gaston_seriesconf!(sp, series, true, 1)
push!(curves, Gaston.Curve(x, y, z, supp, sc))
end
end

for c in curves
for c curves
append = length(gsp.curves) > 0
push!(gsp.curves, c)
Gaston.write_data(c, gsp.dims, gsp.datafile; append)
Expand Down Expand Up @@ -524,7 +524,7 @@ function gaston_parse_axes_attrs(
polar = ispolar(sp) && dims == 2 # cannot splot in polar coordinates

fs = sp[:framestyle]
for letter in (:x, :y, :z)
for letter (:x, :y, :z)
(letter :z && dims == 2) && continue
axis = sp[get_attr_symbol(letter, :axis)]

Expand Down Expand Up @@ -679,7 +679,7 @@ function gaston_parse_axes_attrs(
gaston_ticks = if (ttype = PlotsBase.ticks_type(rticks)) :ticks
string.(rticks)
elseif ttype :ticks_and_labels
["'$l' $t" for (t, l) in zip(rticks...)]
["'$l' $t" for (t, l) zip(rticks...)]
end
push!(
axesconf,
Expand Down Expand Up @@ -799,7 +799,7 @@ function gaston_font(f; rot = true, align = true, color = true, scale = 1)
end

gaston_palette(gradient) =
let palette = ["$(n - 1) $(c.r) $(c.g) $(c.b)" for (n, c) in enumerate(gradient)]
let palette = ["$(n - 1) $(c.r) $(c.g) $(c.b)" for (n, c) enumerate(gradient)]
'(' * join(palette, ", ") * ')'
end

Expand Down
Loading

0 comments on commit 0ab074b

Please sign in to comment.