11function 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
2121end
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))
2727plot (f:: Function , options= Dict ()) = plot ([line (f, options)])
2828plot (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)
6060end
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
7878end
7979
8080if 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
137134end
0 commit comments