Skip to content

Commit 96a2731

Browse files
committed
Clean-up, define all dict literals with {}
1 parent 9780545 commit 96a2731

File tree

2 files changed

+56
-59
lines changed

2 files changed

+56
-59
lines changed

src/Plotly.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ type CurrentPlot
1313
url::String
1414
end
1515

16-
default_options = ["filename"=>"Plot from Julia API",
16+
default_options = {"filename"=>"Plot from Julia API",
1717
"world_readable"=> true,
18-
"layout"=>[""=>""]]
18+
"layout"=>{""=>""}}
1919

2020
## Taken from https://github.com/johnmyleswhite/Vega.jl/blob/master/src/Vega.jl#L51
2121
# Open a URL in a browser
@@ -25,16 +25,16 @@ function openurl(url::String)
2525
@linux_only run(`xdg-open $url`)
2626
end
2727

28-
default_opts = [
28+
default_opts = {
2929
"origin" => "plot",
3030
"platform" => "Julia",
31-
"version" => "0.2"]
31+
"version" => "0.2"}
3232

3333
function signup(username::String, email::String)
3434
r = HTTPClient.HTTPC.post("http://plot.ly/apimkacct",
3535
merge(default_opts,
36-
["un" => username,
37-
"email" => email]))
36+
{"un" => username,
37+
"email" => email}))
3838
if r.http_code == 200
3939
results = JSON.parse(bytestring(r.body))
4040
for flag in ["error","warning","message"]
@@ -63,10 +63,10 @@ function plot(data::Array,options=Dict())
6363
opt = merge(default_options,options)
6464
r = HTTPClient.HTTPC.post("http://plot.ly/clientresp",
6565
merge(default_opts,
66-
["un" => plotlyaccount.username,
66+
{"un" => plotlyaccount.username,
6767
"key" => plotlyaccount.api_key,
6868
"args" => json(data),
69-
"kwargs" => json(opt)]))
69+
"kwargs" => json(opt)}))
7070
body=JSON.parse(bytestring(r.body))
7171
if r.http_code != 200
7272
error(["r.http_code"])
@@ -92,11 +92,11 @@ function layout(layout_opts::Dict,meta_opts=Dict())
9292

9393
r = HTTPClient.HTTPC.post("http://plot.ly/clientresp",
9494
merge(default_opts,
95-
["un" => plotlyaccount.username,
95+
{"un" => plotlyaccount.username,
9696
"key" => plotlyaccount.api_key,
9797
"args" => json(layout_opts),
9898
"origin" => "layout",
99-
"kwargs" => json(meta_opts)]))
99+
"kwargs" => json(meta_opts)}))
100100
__parseresponse(r)
101101
end
102102

@@ -111,11 +111,11 @@ function style(style_opts,meta_opts=Dict())
111111

112112
r = HTTPClient.HTTPC.post("http://plot.ly/clientresp",
113113
merge(default_opts,
114-
["un" => plotlyaccount.username,
114+
{"un" => plotlyaccount.username,
115115
"key" => plotlyaccount.api_key,
116116
"args" => json([style_opts]),
117117
"origin" => "style",
118-
"kwargs" => json(meta_opts)]))
118+
"kwargs" => json(meta_opts)}))
119119
__parseresponse(r)
120120
end
121121

@@ -148,9 +148,9 @@ end
148148

149149
function get_template(format_type::String)
150150
if format_type == "layout"
151-
return [
151+
return {
152152
"title"=>"Click to enter Plot title",
153-
"xaxis"=>[
153+
"xaxis"=>{
154154
"range"=>[-1,6],
155155
"type"=>"-",
156156
"mirror"=>true,
@@ -177,9 +177,9 @@ function get_template(format_type::String)
177177
"zerolinewidth"=>1,
178178
"title"=>"Click to enter X axis title",
179179
"unit"=>"",
180-
"titlefont"=>["family"=>"","size"=>0,"color"=>""],
181-
"tickfont"=>["family"=>"","size"=>0,"color"=>""]],
182-
"yaxis"=>[
180+
"titlefont"=>{"family"=>"","size"=>0,"color"=>""},
181+
"tickfont"=>{"family"=>"","size"=>0,"color"=>""}},
182+
"yaxis"=>{
183183
"range"=>[-1,4],
184184
"type"=>"-",
185185
"mirror"=>true,
@@ -206,18 +206,18 @@ function get_template(format_type::String)
206206
"zerolinewidth"=>1,
207207
"title"=>"Click to enter Y axis title",
208208
"unit"=>"",
209-
"titlefont"=>["family"=>"","size"=>0,"color"=>""],
210-
"tickfont"=>["family"=>"","size"=>0,"color"=>""]],
211-
"legend"=>[
209+
"titlefont"=>{"family"=>"","size"=>0,"color"=>""},
210+
"tickfont"=>{"family"=>"","size"=>0,"color"=>""}},
211+
"legend"=>{
212212
"bgcolor"=>"#fff",
213213
"bordercolor"=>"#000",
214214
"borderwidth"=>1,
215-
"font"=>["family"=>"","size"=>0,"color"=>""],
216-
"traceorder"=>"normal"],
215+
"font"=>{"family"=>"","size"=>0,"color"=>""},
216+
"traceorder"=>"normal"},
217217
"width"=>700,
218218
"height"=>450,
219219
"autosize"=>"initial",
220-
"margin"=>["l"=>80,"r"=>80,"t"=>80,"b"=>80,"pad"=>2],
220+
"margin"=>{"l"=>80,"r"=>80,"t"=>80,"b"=>80,"pad"=>2},
221221
"paper_bgcolor"=>"#fff",
222222
"plot_bgcolor"=>"#fff",
223223
"barmode"=>"stack",
@@ -226,10 +226,10 @@ function get_template(format_type::String)
226226
"boxmode"=>"overlay",
227227
"boxgap"=>0.3,
228228
"boxgroupgap"=>0.3,
229-
"font"=>["family"=>"Arial, sans-serif;","size"=>12,"color"=>"#000"],
230-
"titlefont"=>["family"=>"","size"=>0,"color"=>""],
229+
"font"=>{"family"=>"Arial, sans-serif;","size"=>12,"color"=>"#000"},
230+
"titlefont"=>{"family"=>"","size"=>0,"color"=>""},
231231
"dragmode"=>"zoom",
232-
"hovermode"=>"x"]
232+
"hovermode"=>"x"}
233233
end
234234
end
235235

src/plot.jl

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function get_points(f::Function, options=Dict())
2-
default = ["left"=>-10, "right"=>10, "step"=>0.5, "name"=>"$f", "type"=>"scatter", "mode"=>"lines"]
2+
default = {"left"=>-10, "right"=>10, "step"=>0.5, "name"=>"$f", "type"=>"scatter", "mode"=>"lines"}
33
opt = merge(default, options)
44
n::Int = (opt["right"] - opt["left"]) / opt["step"] + 1
55
X = Float64[0 for i in 1:n]
@@ -12,18 +12,18 @@ function get_points(f::Function, options=Dict())
1212
end
1313

1414
if opt["type"] == "histogram"
15-
return ["x"=>Y, "type"=>opt["type"], "mode"=>opt["mode"], "name"=>opt["name"]]
15+
return {"x"=>Y, "type"=>opt["type"], "mode"=>opt["mode"], "name"=>opt["name"]}
1616
elseif opt["type"] == "box"
17-
return ["y"=>Y, "type"=>opt["type"], "mode"=>opt["mode"], "name"=>opt["name"]]
17+
return {"y"=>Y, "type"=>opt["type"], "mode"=>opt["mode"], "name"=>opt["name"]}
1818
else
19-
return ["x"=>X, "y"=>Y, "type"=>opt["type"], "mode"=>opt["mode"], "name"=>opt["name"]]
19+
return {"x"=>X, "y"=>Y, "type"=>opt["type"], "mode"=>opt["mode"], "name"=>opt["name"]}
2020
end
2121
end
2222

23-
scatter(f::Function, options=Dict()) = get_points(f, merge(["type"=>"scatter","mode"=>"markers","_"=>:_], options))
24-
line(f::Function, options=Dict()) = get_points(f, merge(["type"=>"scatter","mode"=>"lines","_"=>:_], options))
25-
box(f::Function, options=Dict()) = get_points(f, merge(["type"=>"box","_"=>:_], options))
26-
histogram(f::Function, options=Dict()) = get_points(f, merge(["type"=>"histogram","_"=>:_], options))
23+
scatter(f::Function, options=Dict()) = get_points(f, merge({"type"=>"scatter","mode"=>"markers"}, options))
24+
line(f::Function, options=Dict()) = get_points(f, merge({"type"=>"scatter","mode"=>"lines"}, options))
25+
box(f::Function, options=Dict()) = get_points(f, merge({"type"=>"box"}, options))
26+
histogram(f::Function, options=Dict()) = get_points(f, merge({"type"=>"histogram"}, options))
2727
plot(f::Function, options=Dict()) = plot([line(f, options)])
2828
plot(fs::Array{Function,1}, options=Dict()) = plot([line(f, options) for f in fs])
2929

@@ -36,7 +36,7 @@ if Pkg.installed("Polynomial") !== nothing
3636
histogram(p::Poly, options=Dict()) = histogram(x->polyval(p,x), options)
3737

3838
function plot{T<:Number}(ps::Array{Poly{T},1}, options=Dict())
39-
data = [get_points(x->polyval(p,x), merge(["name"=>"$p"], options)) for p in ps]
39+
data = [get_points(x->polyval(p,x), merge({"name"=>"$p"}, options)) for p in ps]
4040
return plot([data], options)
4141
end
4242

@@ -49,13 +49,13 @@ if Pkg.installed("TimeSeries") !== nothing
4949
import TimeSeries: TimeArray, timestamp, values, colnames
5050

5151
scatter(ts::TimeArray, options=Dict()) = [
52-
["x"=>map(t->"$t", timestamp(ts[col])), "y"=>values(ts[col]), "type"=>"scatter", "mode"=>"markers", "name"=>col]
52+
{"x"=>map(t->"$t", timestamp(ts[col])), "y"=>values(ts[col]), "type"=>"scatter", "mode"=>"markers", "name"=>col}
5353
for col in colnames(ts)
5454
]
5555

56-
line(ts::TimeArray, options=Dict()) = [merge(x,["type"=>"line","mode"=>"lines","_"=>:_]) for x in scatter(ts)]
57-
box(ts::TimeArray, options=Dict()) = [merge(x,["type"=>"box","_"=>:_]) for x in scatter(ts)]
58-
histogram(ts::TimeArray, options=Dict()) = [merge(x,["type"=>"histogram","_"=>:_]) for x in scatter(ts)]
56+
line(ts::TimeArray, options=Dict()) = [merge(x,{"type"=>"line","mode"=>"lines"}) for x in scatter(ts)]
57+
box(ts::TimeArray, options=Dict()) = [merge(x,{"type"=>"box"}) for x in scatter(ts)]
58+
histogram(ts::TimeArray, options=Dict()) = [merge(x,{"type"=>"histogram"}) for x in scatter(ts)]
5959
plot(ts::TimeArray, options=Dict()) = plot([line(ts)], options)
6060
end
6161

@@ -64,28 +64,28 @@ if Pkg.installed("WAV") !== nothing
6464
w, Fs = wav
6565
X = [f/Fs for f in 1.0:length(w)]
6666
Y = [round(y,8) for y in w]
67-
["x"=>X, "y"=>Y, "type"=>"scatter", "mode"=>"lines", "name"=>"WAV data"]
67+
return {"x"=>X, "y"=>Y, "type"=>"scatter", "mode"=>"lines", "name"=>"WAV data"}
6868
end
6969

70-
scatter{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict()) = merge(line(wav),["type"=>"scatter","mode"=>"markers","_"=>:_])
71-
box{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict()) = merge(line(wav),["type"=>"box","_"=>:_])
72-
histogram{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict()) = merge(line(wav),["type"=>"histogram","_"=>:_])
70+
scatter{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict()) = merge(line(wav),{"type"=>"scatter","mode"=>"markers"})
71+
box{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict()) = merge(line(wav),{"type"=>"box"})
72+
histogram{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict()) = merge(line(wav),{"type"=>"histogram"})
7373

7474
function plot{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict())
75-
opt = merge(["layout"=>["xaxis"=>["title"=>"seconds","dtick"=>1,"tick0"=>0,"autotick"=>false]]], options)
75+
opt = merge({"layout"=>{"xaxis"=>{"title"=>"seconds","dtick"=>1,"tick0"=>0,"autotick"=>false}}}, options)
7676
return plot([line(wav)], opt)
7777
end
7878
end
7979

8080
if Pkg.installed("DataFrames") !== nothing
8181
import DataFrames: DataFrame
8282

83-
scatter(df::DataFrame, options=Dict()) = get_points(df, merge(["type"=>"scatter","mode"=>"markers","_"=>:_], options))
84-
line(df::DataFrame, options=Dict()) = get_points(df, merge(["type"=>"scatter","mode"=>"lines","_"=>:_], options))
85-
box(df::DataFrame, options=Dict()) = get_points(df, merge(["type"=>"box","_"=>:_], options))
86-
histogram(df::DataFrame, options=Dict()) = get_points(df, merge(["type"=>"histogram","_"=>:_], options))
83+
scatter(df::DataFrame, options=Dict()) = get_points(df, merge({"type"=>"scatter","mode"=>"markers"}, options))
84+
line(df::DataFrame, options=Dict()) = get_points(df, merge({"type"=>"scatter","mode"=>"lines"}, options))
85+
box(df::DataFrame, options=Dict()) = get_points(df, merge({"type"=>"box"}, options))
86+
histogram(df::DataFrame, options=Dict()) = get_points(df, merge({"type"=>"histogram"}, options))
8787
function get_points(df::DataFrame, options=Dict())
88-
default = ["type"=>"scatter", "mode"=>"lines", "_"=>:_]
88+
default = {"type"=>"scatter", "mode"=>"lines"}
8989
opt = merge(default, options)
9090
for axis in ["xs", "ys"]
9191
if haskey(opt, axis) && typeof(opt[axis]) <: Symbol
@@ -96,30 +96,27 @@ if Pkg.installed("DataFrames") !== nothing
9696
if haskey(opt, "xs") && haskey(opt, "ys")
9797
if length(opt["xs"]) == length(opt["ys"])
9898
return [
99-
["x"=>df[opt["xs"][i]], "y"=>df[opt["ys"][i]], "type"=>opt["type"], "mode"=>opt["mode"]]
99+
{"x"=>df[opt["xs"][i]], "y"=>df[opt["ys"][i]], "type"=>opt["type"], "mode"=>opt["mode"]}
100100
for i in 1:length(opt["xs"])
101101
]
102102
else
103103
return [
104-
[
105-
["x"=>df[x], "y"=>df[y], "type"=>opt["type"], "mode"=>opt["mode"]]
106-
for x in opt["xs"]
107-
]
108-
for y in opt["ys"]
104+
{"x"=>df[x], "y"=>df[y], "type"=>opt["type"], "mode"=>opt["mode"]}
105+
for x in opt["xs"], y in opt["ys"]
109106
]
110107
end
111108
elseif haskey(opt, "xs")
112109
return [
113-
["x"=>df[x], "type"=>opt["type"], "mode"=>opt["mode"]]
110+
{"x"=>df[x], "type"=>opt["type"], "mode"=>opt["mode"]}
114111
for x in opt["xs"]
115112
]
116113
elseif haskey(opt, "ys")
117114
return [
118-
["y"=>df[y], "type"=>opt["type"], "mode"=>opt["mode"]]
115+
{"y"=>df[y], "type"=>opt["type"], "mode"=>opt["mode"]}
119116
for y in opt["ys"]
120117
]
121118
else
122-
return ["error"=>"Please set the xs and/or ys options."]
119+
return {"error"=>"Please set the xs and/or ys options."}
123120
end
124121
end
125122

@@ -131,7 +128,7 @@ if Pkg.installed("DataFrames") !== nothing
131128
elseif haskey(options, "ys")
132129
return plot([box(df)], options)
133130
else
134-
return ["error"=>"Please set the xs and/or ys options."]
131+
return {"error"=>"Please set the xs and/or ys options."}
135132
end
136133
end
137134
end

0 commit comments

Comments
 (0)