11module Plotly
2- using HTTPClient
2+ using HTTPClient. HTTPC
33using JSON
44
5- type PlotlyAccount
5+ type PlotlyAccount
66 username:: String
77 api_key:: String
88end
@@ -31,12 +31,12 @@ default_opts = {
3131" version" => " 0.2" }
3232
3333function signup (username:: String , email:: String )
34- r = HTTPClient . HTTPC . post (" http://plot.ly/apimkacct" ,
35- merge (default_opts,
36- {" un" => username,
34+ r = post (" http://plot.ly/apimkacct" ,
35+ merge (default_opts,
36+ {" un" => username,
3737 " email" => email}))
3838 if r. http_code == 200
39- results = JSON. parse (bytestring (r. body))
39+ results = JSON. parse (bytestring (r. body))
4040 for flag in [" error" ," warning" ," message" ]
4141 if haskey (results, flag) && results[flag] != " "
4242 println (results[flag])
@@ -50,7 +50,7 @@ function signup(username::String, email::String)
5050end
5151
5252function signin (username:: String , api_key:: String )
53- global plotlyaccount
53+ global plotlyaccount
5454 plotlyaccount = PlotlyAccount (username,api_key)
5555end
5656
@@ -61,12 +61,15 @@ function plot(data::Array,options=Dict())
6161 return
6262 end
6363 opt = merge (default_options,options)
64- r = HTTPClient. HTTPC. post (" http://plot.ly/clientresp" ,
65- merge (default_opts,
66- {" un" => plotlyaccount. username,
67- " key" => plotlyaccount. api_key,
68- " args" => json (data),
69- " kwargs" => json (opt)}))
64+ r = post (" http://plot.ly/clientresp" ,
65+ merge (default_opts,
66+ {
67+ " un" => plotlyaccount. username,
68+ " key" => plotlyaccount. api_key,
69+ " args" => json (data),
70+ " kwargs" => json (opt)
71+ })
72+ )
7073 body= JSON. parse (bytestring (r. body))
7174 if r. http_code != 200
7275 error ([" r.http_code" ])
@@ -90,7 +93,7 @@ function layout(layout_opts::Dict,meta_opts=Dict())
9093
9194 merge! (meta_opts,get_required_params ([" filename" ," fileopt" ],meta_opts))
9295
93- r = HTTPClient . HTTPC . post (" http://plot.ly/clientresp" ,
96+ r = post (" http://plot.ly/clientresp" ,
9497 merge (default_opts,
9598 {" un" => plotlyaccount. username,
9699 " key" => plotlyaccount. api_key,
@@ -109,7 +112,7 @@ function style(style_opts,meta_opts=Dict())
109112
110113 merge! (meta_opts,get_required_params ([" filename" ," fileopt" ],meta_opts))
111114
112- r = HTTPClient . HTTPC . post (" http://plot.ly/clientresp" ,
115+ r = post (" http://plot.ly/clientresp" ,
113116 merge (default_opts,
114117 {" un" => plotlyaccount. username,
115118 " key" => plotlyaccount. api_key,
122125function get_required_params (required,opts)
123126 # Priority given to user-inputted opts, then currentplot
124127 result= Dict ()
125- for p in required
128+ for p in required
126129 global currentplot
127130 if haskey (opts,p)
128131 result[p] = opts[p]
@@ -139,84 +142,86 @@ function __parseresponse(r)
139142 body= JSON. parse (bytestring (r. body))
140143 if r. http_code != 200
141144 error ([" r.http_code" ])
142- elseif body[" error" ] != " "
145+ elseif haskey (body, " error " ) && body[" error" ] != " "
143146 error (body[" error" ])
147+ elseif haskey (body, " detail" ) && body[" detail" ] != " "
148+ error (body[" detail" ])
144149 else
145150 body
146151 end
147152end
148153
149154function get_template (format_type:: String )
150- if format_type == " layout"
155+ if format_type == " layout"
151156 return {
152157 " title" => " Click to enter Plot title" ,
153158 " xaxis" => {
154159 " range" => [- 1 ,6 ],
155160 " type" => " -" ,
156161 " mirror" => true ,
157162 " linecolor" => " #000" ,
158- " linewidth" => 1 ,
163+ " linewidth" => 1 ,
159164 " tick0" => 0 ,
160165 " dtick" => 2 ,
161166 " ticks" => " outside" ,
162167 " ticklen" => 5 ,
163168 " tickwidth" => 1 ,
164169 " tickcolor" => " #000" ,
165- " nticks" => 0 ,
170+ " nticks" => 0 ,
166171 " showticklabels" => true ,
167172 " tickangle" => " auto" ,
168173 " exponentformat" => " e" ,
169- " showexponent" => " all" ,
174+ " showexponent" => " all" ,
170175 " showgrid" => true ,
171176 " gridcolor" => " #ddd" ,
172- " gridwidth" => 1 ,
177+ " gridwidth" => 1 ,
173178 " autorange" => true ,
174- " autotick" => true ,
179+ " autotick" => true ,
175180 " zeroline" => true ,
176181 " zerolinecolor" => " #000" ,
177- " zerolinewidth" => 1 ,
182+ " zerolinewidth" => 1 ,
178183 " title" => " Click to enter X axis title" ,
179- " unit" => " " ,
180- " titlefont" => {" family" => " " ," size" => 0 ," color" => " " },
181- " tickfont" => {" family" => " " ," size" => 0 ," color" => " " }},
184+ " unit" => " " ,
185+ " titlefont" => {" family" => " " ," size" => 0 ," color" => " " },
186+ " tickfont" => {" family" => " " ," size" => 0 ," color" => " " }},
182187 " yaxis" => {
183188 " range" => [- 1 ,4 ],
184189 " type" => " -" ,
185190 " mirror" => true ,
186191 " linecolor" => " #000" ,
187- " linewidth" => 1 ,
192+ " linewidth" => 1 ,
188193 " tick0" => 0 ,
189194 " dtick" => 1 ,
190195 " ticks" => " outside" ,
191196 " ticklen" => 5 ,
192197 " tickwidth" => 1 ,
193198 " tickcolor" => " #000" ,
194- " nticks" => 0 ,
199+ " nticks" => 0 ,
195200 " showticklabels" => true ,
196201 " tickangle" => " auto" ,
197202 " exponentformat" => " e" ,
198- " showexponent" => " all" ,
203+ " showexponent" => " all" ,
199204 " showgrid" => true ,
200205 " gridcolor" => " #ddd" ,
201- " gridwidth" => 1 ,
206+ " gridwidth" => 1 ,
202207 " autorange" => true ,
203- " autotick" => true ,
208+ " autotick" => true ,
204209 " zeroline" => true ,
205210 " zerolinecolor" => " #000" ,
206- " zerolinewidth" => 1 ,
211+ " zerolinewidth" => 1 ,
207212 " title" => " Click to enter Y axis title" ,
208- " unit" => " " ,
209- " titlefont" => {" family" => " " ," size" => 0 ," color" => " " },
210- " tickfont" => {" family" => " " ," size" => 0 ," color" => " " }},
213+ " unit" => " " ,
214+ " titlefont" => {" family" => " " ," size" => 0 ," color" => " " },
215+ " tickfont" => {" family" => " " ," size" => 0 ," color" => " " }},
211216 " legend" => {
212- " bgcolor" => " #fff" ,
213- " bordercolor" => " #000" ,
214- " borderwidth" => 1 ,
215- " font" => {" family" => " " ," size" => 0 ," color" => " " },
217+ " bgcolor" => " #fff" ,
218+ " bordercolor" => " #000" ,
219+ " borderwidth" => 1 ,
220+ " font" => {" family" => " " ," size" => 0 ," color" => " " },
216221 " traceorder" => " normal" },
217222 " width" => 700 ,
218223 " height" => 450 ,
219- " autosize" => " initial" ,
224+ " autosize" => " initial" ,
220225 " margin" => {" l" => 80 ," r" => 80 ," t" => 80 ," b" => 80 ," pad" => 2 },
221226 " paper_bgcolor" => " #fff" ,
222227 " plot_bgcolor" => " #fff" ,
0 commit comments