replace 1:length with linearindices

This commit is contained in:
Michael K. Borregaard 2017-09-02 12:57:28 +02:00
parent d25a3e006f
commit 55d634c17a
10 changed files with 24 additions and 24 deletions

View File

@ -866,7 +866,7 @@ function extractGroupArgs(v::AVec, args...; legendEntry = string)
if n > 100 if n > 100
warn("You created n=$n groups... Is that intended?") warn("You created n=$n groups... Is that intended?")
end 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) GroupBy(map(legendEntry, groupLabels), groupIds)
end 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 # this is when given a tuple of vectors of values to group by
function extractGroupArgs(vs::Tuple, args...) function extractGroupArgs(vs::Tuple, args...)
(vs == ()) && return GroupBy([""], [1:size(args[1],1)]) (vs == ()) && return GroupBy([""], [indices(args[1],1)])
v = collect(zip(vs...)) v = collect(zip(vs...))
extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple) extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple)
end end

View File

@ -802,7 +802,7 @@ function gl_bar(d, kw_args)
hw = if bw == nothing hw = if bw == nothing
ignorenan_mean(diff(x)) ignorenan_mean(diff(x))
else else
Float64[_cycle(bw,i)*0.5 for i=1:length(x)] Float64[_cycle(bw,i)*0.5 for i=linearindices(x)]
end end
# make fillto a vector... default fills to 0 # 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] sx, sy = m[1,1], m[2,2]
for (i,glabel) in enumerate(glabels) for (i,glabel) in enumerate(glabels)
# filter y # 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 # compute quantiles
q1,q2,q3,q4,q5 = quantile(values, linspace(0,1,5)) q1,q2,q3,q4,q5 = quantile(values, linspace(0,1,5))
# notch # notch
@ -963,7 +963,7 @@ function scale_for_annotations!(series::Series, scaletype::Symbol = :pixels)
# with a list of custom shapes for each # with a list of custom shapes for each
msw, msh = anns.scalefactor msw, msh = anns.scalefactor
offsets = Array{Vec2f0}(length(anns.strs)) 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) str = _cycle(anns.strs, i)
# get the width and height of the string (in mm) # get the width and height of the string (in mm)
sw, sh = text_size(str, anns.font.pointsize) sw, sh = text_size(str, anns.font.pointsize)

View File

@ -370,7 +370,7 @@ end
function plotly_colorscale(grad::ColorGradient, α) 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 end
plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α) plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α)
# plotly_colorscale(c, alpha = nothing) = 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 # we split by NaNs and then construct/destruct the shapes to get the closed coords
function plotly_close_shapes(x, y) function plotly_close_shapes(x, y)
xs, ys = nansplit(x), nansplit(y) xs, ys = nansplit(x), nansplit(y)
for i=1:length(xs) for i=linearindices(xs)
shape = Shape(xs[i], ys[i]) shape = Shape(xs[i], ys[i])
xs[i], ys[i] = coords(shape) xs[i], ys[i] = coords(shape)
end end

View File

@ -244,7 +244,7 @@ end
# end # end
function get_locator_and_formatter(vals::AVec) function get_locator_and_formatter(vals::AVec)
pyticker["FixedLocator"](1:length(vals)), pyticker["FixedFormatter"](vals) pyticker["FixedLocator"](linearindices(vals)), pyticker["FixedFormatter"](vals)
end end
function add_pyfixedformatter(cbar, vals::AVec) function add_pyfixedformatter(cbar, vals::AVec)
@ -589,7 +589,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
shapes = series[:markershape] shapes = series[:markershape]
msc = py_markerstrokecolor(series) msc = py_markerstrokecolor(series)
lw = py_dpi_scale(plt, series[:markerstrokewidth]) lw = py_dpi_scale(plt, series[:markerstrokewidth])
for i=1:length(y) for i=linearindices(y)
extrakw[:c] = if series[:marker_z] == nothing extrakw[:c] = if series[:marker_z] == nothing
py_color_fix(py_color(_cycle(series[:markercolor],i)), x) py_color_fix(py_color(_cycle(series[:markercolor],i)), x)
else else
@ -850,7 +850,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
kw = KW() kw = KW()
if discrete_colorbar_values != nothing if discrete_colorbar_values != nothing
locator, formatter = get_locator_and_formatter(discrete_colorbar_values) 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[:values] = sp[:zaxis][:continuous_values]
kw[:ticks] = locator kw[:ticks] = locator
kw[:format] = formatter kw[:format] = formatter

View File

@ -186,7 +186,7 @@ end
function scale!(shape::Shape, x::Real, y::Real = x, c = center(shape)) function scale!(shape::Shape, x::Real, y::Real = x, c = center(shape))
sx, sy = coords(shape) sx, sy = coords(shape)
cx, cy = c cx, cy = c
for i=1:length(sx) for i=linearindices(sx)
sx[i] = (sx[i] - cx) * x + cx sx[i] = (sx[i] - cx) * x + cx
sy[i] = (sy[i] - cy) * y + cy sy[i] = (sy[i] - cy) * y + cy
end end
@ -201,7 +201,7 @@ end
"translate a Shape in space" "translate a Shape in space"
function translate!(shape::Shape, x::Real, y::Real = x) function translate!(shape::Shape, x::Real, y::Real = x)
sx, sy = coords(shape) sx, sy = coords(shape)
for i=1:length(sx) for i=linearindices(sx)
sx[i] += x sx[i] += x
sy[i] += y sy[i] += y
end end
@ -229,7 +229,7 @@ end
function rotate!(shape::Shape, Θ::Real, c = center(shape)) function rotate!(shape::Shape, Θ::Real, c = center(shape))
x, y = coords(shape) x, y = coords(shape)
cx, cy = c cx, cy = c
for i=1:length(x) for i=linearindices(x)
xi = rotate_x(x[i], y[i], Θ, cx, cy) xi = rotate_x(x[i], y[i], Θ, cx, cy)
yi = rotate_y(x[i], y[i], Θ, cx, cy) yi = rotate_y(x[i], y[i], Θ, cx, cy)
x[i], y[i] = xi, yi x[i], y[i] = xi, yi
@ -506,7 +506,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
push!(msize, maxscale) push!(msize, maxscale)
baseshape = _cycle(get(anns.baseshape),i) baseshape = _cycle(get(anns.baseshape),i)
shape = scale(baseshape, msw*xscale/maxscale, msh*yscale/maxscale, (0,0)) 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[:markershape] = shapes
series[:markersize] = msize series[:markersize] = msize
end end

View File

@ -258,7 +258,7 @@ function addToGadflyLegend(plt::Plot, d::KW)
foundit = false foundit = false
# extend the label if we found this color # 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] if RGB(c) == guide.colors[i]
guide.labels[i] *= ", " * d[:label] guide.labels[i] *= ", " * d[:label]
foundit = true foundit = true
@ -333,9 +333,9 @@ end
# # this is super weird, but... oh well... for some reason this creates n separate line segments... # # 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) # # 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] # # 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] # 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])) # d[:x], d[:y] = map(createSegments, (d[:x], d[:y]))
# colorgroup = [(:linecolor, cs), (:group, grp)] # colorgroup = [(:linecolor, cs), (:group, grp)]

View File

@ -379,7 +379,7 @@ function test_examples(pkgname::Symbol; debug = false, disp = true, sleep = noth
skip = [], only = nothing) skip = [], only = nothing)
Plots._debugMode.on = debug Plots._debugMode.on = debug
plts = Dict() plts = Dict()
for i in 1:length(_examples) for i in linearindices(_examples)
only != nothing && !(i in only) && continue only != nothing && !(i in only) && continue
i in skip && continue i in skip && continue
try try

View File

@ -291,7 +291,7 @@ end
hw = if bw == nothing hw = if bw == nothing
0.5ignorenan_mean(diff(procx)) 0.5ignorenan_mean(diff(procx))
else else
Float64[0.5_cycle(bw,i) for i=1:length(procx)] Float64[0.5_cycle(bw,i) for i=linearindices(procx)]
end end
# make fillto a vector... default fills to 0 # make fillto a vector... default fills to 0
@ -872,7 +872,7 @@ function get_xy(o::OHLC, x, xdiff)
end end
# get the joined vector # 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))) xdiff = 0.3ignorenan_mean(abs.(diff(x)))
x_out, y_out = zeros(0), zeros(0) x_out, y_out = zeros(0), zeros(0)
for (i,ohlc) in enumerate(v) for (i,ohlc) in enumerate(v)

View File

@ -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" "Make histogram-like bins of data"
function binData(data, nbins) function binData(data, nbins)
@ -43,7 +43,7 @@ function barHack(; kw...)
# estimate the edges # estimate the edges
dists = diff(midpoints) * 0.5 dists = diff(midpoints) * 0.5
edges = zeros(length(midpoints)+1) edges = zeros(length(midpoints)+1)
for i in 1:length(edges) for i in linearindices(edges)
if i == 1 if i == 1
edge = midpoints[1] - dists[1] edge = midpoints[1] - dists[1]
elseif i == length(edges) elseif i == length(edges)
@ -56,7 +56,7 @@ function barHack(; kw...)
x = Float64[] x = Float64[]
y = Float64[] y = Float64[]
for i in 1:length(heights) for i in linearindices(heights)
e1, e2 = edges[i:i+1] e1, e2 = edges[i:i+1]
append!(x, [e1, e1, e2, e2]) append!(x, [e1, e1, e2, e2])
append!(y, [fillrange, heights[i], heights[i], fillrange]) append!(y, [fillrange, heights[i], heights[i], fillrange])

View File

@ -92,7 +92,7 @@ function image_comparison_facts(pkg::Symbol;
debug = false, # print debug information? debug = false, # print debug information?
sigma = [1,1], # number of pixels to "blur" sigma = [1,1], # number of pixels to "blur"
eps = 1e-2) # acceptable error (percent) eps = 1e-2) # acceptable error (percent)
for i in 1:length(Plots._examples) for i in linearindices(Plots._examples)
i in skip && continue i in skip && continue
if only == nothing || i in only if only == nothing || i in only
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success == true @test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success == true