replace 1:length with linearindices
This commit is contained in:
parent
d25a3e006f
commit
55d634c17a
@ -866,7 +866,7 @@ function extractGroupArgs(v::AVec, args...; legendEntry = string)
|
||||
if n > 100
|
||||
warn("You created n=$n groups... Is that intended?")
|
||||
end
|
||||
groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels]
|
||||
groupIds = Vector{Int}[filter(i -> v[i] == glab, linearindices(v)) for glab in groupLabels]
|
||||
GroupBy(map(legendEntry, groupLabels), groupIds)
|
||||
end
|
||||
|
||||
@ -874,7 +874,7 @@ legendEntryFromTuple(ns::Tuple) = string(("$n " for n in ns)...)
|
||||
|
||||
# this is when given a tuple of vectors of values to group by
|
||||
function extractGroupArgs(vs::Tuple, args...)
|
||||
(vs == ()) && return GroupBy([""], [1:size(args[1],1)])
|
||||
(vs == ()) && return GroupBy([""], [indices(args[1],1)])
|
||||
v = collect(zip(vs...))
|
||||
extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple)
|
||||
end
|
||||
|
||||
@ -802,7 +802,7 @@ function gl_bar(d, kw_args)
|
||||
hw = if bw == nothing
|
||||
ignorenan_mean(diff(x))
|
||||
else
|
||||
Float64[_cycle(bw,i)*0.5 for i=1:length(x)]
|
||||
Float64[_cycle(bw,i)*0.5 for i=linearindices(x)]
|
||||
end
|
||||
|
||||
# make fillto a vector... default fills to 0
|
||||
@ -852,7 +852,7 @@ function gl_boxplot(d, kw_args)
|
||||
sx, sy = m[1,1], m[2,2]
|
||||
for (i,glabel) in enumerate(glabels)
|
||||
# filter y
|
||||
values = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))]
|
||||
values = y[filter(i -> _cycle(x,i) == glabel, linearindices(y))]
|
||||
# compute quantiles
|
||||
q1,q2,q3,q4,q5 = quantile(values, linspace(0,1,5))
|
||||
# notch
|
||||
@ -963,7 +963,7 @@ function scale_for_annotations!(series::Series, scaletype::Symbol = :pixels)
|
||||
# with a list of custom shapes for each
|
||||
msw, msh = anns.scalefactor
|
||||
offsets = Array{Vec2f0}(length(anns.strs))
|
||||
series[:markersize] = map(1:length(anns.strs)) do i
|
||||
series[:markersize] = map(linearindices(anns.strs)) do i
|
||||
str = _cycle(anns.strs, i)
|
||||
# get the width and height of the string (in mm)
|
||||
sw, sh = text_size(str, anns.font.pointsize)
|
||||
|
||||
@ -370,7 +370,7 @@ end
|
||||
|
||||
|
||||
function plotly_colorscale(grad::ColorGradient, α)
|
||||
[[grad.values[i], rgb_string(grad.colors[i])] for i in 1:length(grad.colors)]
|
||||
[[grad.values[i], rgb_string(grad.colors[i])] for i in linearindices(grad.colors)]
|
||||
end
|
||||
plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α)
|
||||
# plotly_colorscale(c, alpha = nothing) = plotly_colorscale(cgrad(), alpha)
|
||||
@ -397,7 +397,7 @@ end
|
||||
# we split by NaNs and then construct/destruct the shapes to get the closed coords
|
||||
function plotly_close_shapes(x, y)
|
||||
xs, ys = nansplit(x), nansplit(y)
|
||||
for i=1:length(xs)
|
||||
for i=linearindices(xs)
|
||||
shape = Shape(xs[i], ys[i])
|
||||
xs[i], ys[i] = coords(shape)
|
||||
end
|
||||
|
||||
@ -244,7 +244,7 @@ end
|
||||
# end
|
||||
|
||||
function get_locator_and_formatter(vals::AVec)
|
||||
pyticker["FixedLocator"](1:length(vals)), pyticker["FixedFormatter"](vals)
|
||||
pyticker["FixedLocator"](linearindices(vals)), pyticker["FixedFormatter"](vals)
|
||||
end
|
||||
|
||||
function add_pyfixedformatter(cbar, vals::AVec)
|
||||
@ -589,7 +589,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
shapes = series[:markershape]
|
||||
msc = py_markerstrokecolor(series)
|
||||
lw = py_dpi_scale(plt, series[:markerstrokewidth])
|
||||
for i=1:length(y)
|
||||
for i=linearindices(y)
|
||||
extrakw[:c] = if series[:marker_z] == nothing
|
||||
py_color_fix(py_color(_cycle(series[:markercolor],i)), x)
|
||||
else
|
||||
@ -850,7 +850,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
||||
kw = KW()
|
||||
if discrete_colorbar_values != nothing
|
||||
locator, formatter = get_locator_and_formatter(discrete_colorbar_values)
|
||||
# kw[:values] = 1:length(discrete_colorbar_values)
|
||||
# kw[:values] = linearindices(discrete_colorbar_values)
|
||||
kw[:values] = sp[:zaxis][:continuous_values]
|
||||
kw[:ticks] = locator
|
||||
kw[:format] = formatter
|
||||
|
||||
@ -186,7 +186,7 @@ end
|
||||
function scale!(shape::Shape, x::Real, y::Real = x, c = center(shape))
|
||||
sx, sy = coords(shape)
|
||||
cx, cy = c
|
||||
for i=1:length(sx)
|
||||
for i=linearindices(sx)
|
||||
sx[i] = (sx[i] - cx) * x + cx
|
||||
sy[i] = (sy[i] - cy) * y + cy
|
||||
end
|
||||
@ -201,7 +201,7 @@ end
|
||||
"translate a Shape in space"
|
||||
function translate!(shape::Shape, x::Real, y::Real = x)
|
||||
sx, sy = coords(shape)
|
||||
for i=1:length(sx)
|
||||
for i=linearindices(sx)
|
||||
sx[i] += x
|
||||
sy[i] += y
|
||||
end
|
||||
@ -229,7 +229,7 @@ end
|
||||
function rotate!(shape::Shape, Θ::Real, c = center(shape))
|
||||
x, y = coords(shape)
|
||||
cx, cy = c
|
||||
for i=1:length(x)
|
||||
for i=linearindices(x)
|
||||
xi = rotate_x(x[i], y[i], Θ, cx, cy)
|
||||
yi = rotate_y(x[i], y[i], Θ, cx, cy)
|
||||
x[i], y[i] = xi, yi
|
||||
@ -506,7 +506,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
|
||||
push!(msize, maxscale)
|
||||
baseshape = _cycle(get(anns.baseshape),i)
|
||||
shape = scale(baseshape, msw*xscale/maxscale, msh*yscale/maxscale, (0,0))
|
||||
end for i=1:length(anns.strs)]
|
||||
end for i=linearindices(anns.strs)]
|
||||
series[:markershape] = shapes
|
||||
series[:markersize] = msize
|
||||
end
|
||||
|
||||
@ -258,7 +258,7 @@ function addToGadflyLegend(plt::Plot, d::KW)
|
||||
foundit = false
|
||||
|
||||
# extend the label if we found this color
|
||||
for i in 1:length(guide.colors)
|
||||
for i in linearindices(guide.colors)
|
||||
if RGB(c) == guide.colors[i]
|
||||
guide.labels[i] *= ", " * d[:label]
|
||||
foundit = true
|
||||
@ -333,9 +333,9 @@ end
|
||||
# # this is super weird, but... oh well... for some reason this creates n separate line segments...
|
||||
# # create a list of vertices that go: [x1,x2,x2,x3,x3, ... ,xi,xi, ... xn,xn] (same for y)
|
||||
# # then the vector passed to the "color" keyword should be a vector: [1,1,2,2,3,3,4,4, ..., i,i, ... , n,n]
|
||||
# csindices = Int[mod1(i,length(cscheme.v)) for i in 1:length(d[:y])]
|
||||
# csindices = Int[mod1(i,length(cscheme.v)) for i in linearindices(d[:y])]
|
||||
# cs = collect(repmat(csindices', 2, 1))[1:end-1]
|
||||
# grp = collect(repmat((1:length(d[:y]))', 2, 1))[1:end-1]
|
||||
# grp = collect(repmat((linearindices(d[:y]))', 2, 1))[1:end-1]
|
||||
# d[:x], d[:y] = map(createSegments, (d[:x], d[:y]))
|
||||
# colorgroup = [(:linecolor, cs), (:group, grp)]
|
||||
|
||||
|
||||
@ -379,7 +379,7 @@ function test_examples(pkgname::Symbol; debug = false, disp = true, sleep = noth
|
||||
skip = [], only = nothing)
|
||||
Plots._debugMode.on = debug
|
||||
plts = Dict()
|
||||
for i in 1:length(_examples)
|
||||
for i in linearindices(_examples)
|
||||
only != nothing && !(i in only) && continue
|
||||
i in skip && continue
|
||||
try
|
||||
|
||||
@ -291,7 +291,7 @@ end
|
||||
hw = if bw == nothing
|
||||
0.5ignorenan_mean(diff(procx))
|
||||
else
|
||||
Float64[0.5_cycle(bw,i) for i=1:length(procx)]
|
||||
Float64[0.5_cycle(bw,i) for i=linearindices(procx)]
|
||||
end
|
||||
|
||||
# make fillto a vector... default fills to 0
|
||||
@ -872,7 +872,7 @@ function get_xy(o::OHLC, x, xdiff)
|
||||
end
|
||||
|
||||
# get the joined vector
|
||||
function get_xy(v::AVec{OHLC}, x = 1:length(v))
|
||||
function get_xy(v::AVec{OHLC}, x = linearindices(v))
|
||||
xdiff = 0.3ignorenan_mean(abs.(diff(x)))
|
||||
x_out, y_out = zeros(0), zeros(0)
|
||||
for (i,ohlc) in enumerate(v)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for i in 1:length(edges)-1]
|
||||
calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for i in linearindices(edges)-1]
|
||||
|
||||
"Make histogram-like bins of data"
|
||||
function binData(data, nbins)
|
||||
@ -43,7 +43,7 @@ function barHack(; kw...)
|
||||
# estimate the edges
|
||||
dists = diff(midpoints) * 0.5
|
||||
edges = zeros(length(midpoints)+1)
|
||||
for i in 1:length(edges)
|
||||
for i in linearindices(edges)
|
||||
if i == 1
|
||||
edge = midpoints[1] - dists[1]
|
||||
elseif i == length(edges)
|
||||
@ -56,7 +56,7 @@ function barHack(; kw...)
|
||||
|
||||
x = Float64[]
|
||||
y = Float64[]
|
||||
for i in 1:length(heights)
|
||||
for i in linearindices(heights)
|
||||
e1, e2 = edges[i:i+1]
|
||||
append!(x, [e1, e1, e2, e2])
|
||||
append!(y, [fillrange, heights[i], heights[i], fillrange])
|
||||
|
||||
@ -92,7 +92,7 @@ function image_comparison_facts(pkg::Symbol;
|
||||
debug = false, # print debug information?
|
||||
sigma = [1,1], # number of pixels to "blur"
|
||||
eps = 1e-2) # acceptable error (percent)
|
||||
for i in 1:length(Plots._examples)
|
||||
for i in linearindices(Plots._examples)
|
||||
i in skip && continue
|
||||
if only == nothing || i in only
|
||||
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success == true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user