-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVGraph test.ahk
269 lines (224 loc) · 7.78 KB
/
SVGraph test.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
SetBatchLines, -1
#include SVGraph.ahk
#include *i <Gdip>
Plots := [], locked := False
Gui, 1:New, +Resize, SVGraph
Gui, Add, Text, x+m y+m, FunX
Gui, Add, Combobox, ys-2 w200 vEditX, x||Math.sin(x)|Math.cos(x)|Math.pow(x,2)/100 + 0.1|Math.pow(x,3)/100 + Math.pow(x,2)/100 + x/100
Gui, Add, Text, ys x+20, FunY
Gui, Add, Combobox, ys-2 w200 vEditY, Math.sin(x)||Math.cos(x)|Math.pow(x,2)/100 + 0.1|Math.pow(x,3)/100 + Math.pow(x,2)/100 + x/100|x
Gui, Add, Text, ys x+20, Colour
Gui, Add, Combobox, ys-2 w70 vColour, #0000FF||#FF0000|#00FF00
Gui, Add, Text, ys x+20, Resolution
Gui, Add, Edit, ys-2 w70 vResolution, 200
Gui, Add, Text, ys x+20, Axis
Gui, Add, Combobox, ys-2 w70 vAxis, x||y|[min,max]
Gui, Add, Checkbox, ys+3 x+15 vOptimize, Optimize
Gui, Add, Button, ys-2 x+5 gPlot, Plot
Gui, Add, Button, ys-2 x+20 gDeletePlt, Delete
Gui, Add, Text, xs+m Section, xmin
Gui, Add, Edit, ys-2 w70 vxmin gAxes, -10
Gui, Add, Text, ys, xmax
Gui, Add, Edit, ys-2 w70 vxmax gAxes, 10
Gui, Add, Text, ys, ymin
Gui, Add, Edit, ys-2 w70 vymin gAxes, -1
Gui, Add, Text, ys, ymax
Gui, Add, Edit, ys-2 w70 vymax gAxes, 1
Gui, Add, Checkbox, ys+3 x+15 vboxed gAxes, Boxed
Gui, Add, Checkbox, ys+3 x+15 vGrid gGrid, Grid
Gui, Add, Button, ys-2 x+5 gShowMsg vScatter, ScatterImage
Gui, Add, Button, ys-2 x+5 gShowMsg vLable, Labels, Ticks and Margin
Gui, Add, Button, ys-2 x+5 vSave gSave, Save
Gui, Add, Checkbox, ys+3 x+20 vScrollvar gScroll, Scroll
; Call sequence needed before making any plots
Gui, Add, ActiveX, xs w500 h500 vIE, Shell.Explorer
SVGraph_Attach(IE)
SVGraph_Start()
SVGraph_Chart(960, 500, 40)
SVGraph_ShowScrollbar(False)
Gui, Show, AutoSize
;-------------------------------- MSGs ----------------------------------------------
Gui, Scatter:+Owner1
Gui, Scatter:Font, s20
Gui, Scatter:Add, Text, , Scatter Image
Gui, Scatter:Font, s9
Gui, Scatter:Add, Text, y+m, Image:
Gui, Scatter:Add, Edit, x+m vScatterImage
Gui, Scatter:Add, Button, x+m gSelectImage, Browse
Gui, Scatter:Add, Text, xs, Resolution:
Gui, Scatter:Add, Edit, x+m w70 vScatterResolution, 200
Gui, Scatter:Add, Text, xs, Circle Size:
Gui, Scatter:Add, Edit, x+m w40 vScatterSize, 3
Gui, Scatter:Add, Text, xs, Background Colour:
Gui, Scatter:Add, Edit, x+m vScatterBackground, #FFFFFF
Gui Scatter:Add, Button, xs gScatter, Scatter
Gui Scatter:Add, Button, x+m gCancel, Cancel
Gui, Lable:+Owner1
Gui, Lable:Font, s20
Gui, Lable:Add, Text, , Labels and Ticks
Gui, Lable:Font, s9
Gui, Lable:Add, Text, xs, x-lable:
Gui, Lable:Add, Edit, x+m w70 vLableXlable,
Gui, Lable:Add, Text, xs, y-lable:
Gui, Lable:Add, Edit, x+m w70 vLableYlable,
Gui, Lable:Add, Text, xs y+40, Axis:
Gui, Lable:Add, Combobox, x+m w70 vLableXorY, ||x|y
Gui, Lable:Add, Text, xs, Approx # of Ticks:
Gui, Lable:Add, Combobox, x+m w70 vLableMajor, 10||[-5,0,5]
Gui, Lable:Add, Text, xs, # of Minor Ticks:
Gui, Lable:Add, Edit, x+m w40 vLableMinor, 0
Gui, Lable:Add, Text, xs, Grid Colour:
Gui, Lable:Add, Combobox, x+m vLableColour, lightgrey||#FF00FF
Gui, Lable:Add, Text, xs, Grid Style:
Gui, Lable:Add, Combobox, x+m vLableDasharray, 5||0|1,1,1,5,3,3
Gui, Lable:Add, Text, xs y+40, Margin:
Gui, Lable:Add, Combobox, x+m w150 vLableMargin, 40||{top: , left: , bottom: , right: }
Gui, Lable:Add, Button, xs gLable, Set
Gui, Lable:Add, Button, x+m gCancel, Cancel
return
;-------------------------------------------------------------------------------------
GuiSize:
if(!locked){
GuiControlGet, top, Pos, Save
GuiControlGet, side, Pos, IE
GuiControl, Move, IE, % "w" A_GuiWidth - 2*sideX " h" A_GuiHeight - (topY + 2*sideX)
SVGraph_UpdateChart(A_GuiWidth - 2*sideX - 20, A_GuiHeight - topY - 2*sideX - 20)
SetTimer, Axes, -100
}
return
Axes:
if(!locked){
Gui, Submit, NoHide
SVGraph_SetAxes(xmin, xmax, ymin, ymax, boxed)
SVGraph_RemovePath()
IE.Document.parentWindow.eval("plot.ID = 0;")
for index, plot in Plots {
SVGraph_LinePlot(plot[1], plot[2], plot[3], plot[4], plot[5], plot[6])
}
}
return
Scroll:
Gui, Submit, NoHide
SVGraph_ShowScrollbar(Scrollvar)
return
Grid:
Gui, Submit, NoHide
SVGraph_ShowGrid(Grid)
return
Save:
Gui, Submit, NoHide
if("D" != FileExist("\SVGs")){
FileCreateDir, SVGs
}
FileSelectFile, FileName, S16, % "\SVGs\" Get_Unique_Name("SVGs\plot.svg"), Save SVG, *.svg
if(FileName){
SVGraph_SaveSVG(FileName)
}
return
Plot:
Gui, Submit, NoHide
SVGraph_LinePlot(EditX, EditY, Colour ? Colour : "#999", Resolution, Axis, Optimize)
Plots.Push([EditX, EditY, Colour ? Colour : "#999", Resolution, Axis, Optimize])
return
DeletePlt:
Plots.Pop()
SVGraph_RemovePath(-1)
return
;-------------------------------- MSGs ----------------------------------------------
ShowMsg:
GuiControlGet, Ctrl, FocusV
Gui, %Ctrl%:Show, AutoSize
return
Cancel:
Gui, %A_Gui%:Show, Hide
return
SelectImage:
FileSelectFile, image, , , Select Image
GuiControl, , ScatterImage, %image%
return
Scatter:
Gui, Scatter:Submit
ScatterImage(ScatterImage, ScatterResolution, ScatterSize, ScatterBackground)
return
Lable:
Gui, Lable:Submit
SVGraph_UpdateChart(, , LableMargin)
SVGraph_SetLabels(LableXlable, LableYlable)
SVGraph_SetGrid(LableXorY, LableMajor, LableMinor, LableColour, LableDasharray)
return
;-------------------------------------------------------------------------------------
GuiClose:
GuiEscape:
ExitApp
ScatterImage(image, axisResolution, size := 3, background := "#FFFFFF"){
Global locked
Static Gdip_Startup := Func("Gdip_Startup")
, Gdip_CreateBitmapFromFile := Func("Gdip_CreateBitmapFromFile")
, Gdip_GetImageWidth := Func("Gdip_GetImageWidth")
, Gdip_GetImageHeight := Func("Gdip_GetImageHeight")
, Gdip_GetPixel := Func("Gdip_GetPixel")
, Gdip_DisposeImage := Func("Gdip_DisposeImage")
, Gdip_Shutdown := Func("Gdip_Shutdown")
if(Gdip_Startup && Gdip_CreateBitmapFromFile && Gdip_GetImageWidth && Gdip_GetImageHeight && Gdip_GetPixel && Gdip_DisposeImage && Gdip_Shutdown){
locked := True
icon := {}
pToken := Gdip_Startup.Call()
pBitmap := Gdip_CreateBitmapFromFile.Call(image)
xmax := Gdip_GetImageWidth.Call(pBitmap)
ymax := Gdip_GetImageHeight.Call(pBitmap)
step := (xmax > ymax ? xmax : ymax) / axisResolution
SVGraph_UpdateChart(xmax, ymax)
SVGraph_SetAxes(0, xmax, 0, ymax, True)
loop %axisResolution% {
y := (A_Index - 1) * step
loop %axisResolution% {
x := (A_Index - 1) * step
if(((c := ARGBtoRGB(Gdip_GetPixel.Call(pBitmap, x, y)))[1] != 0) && c[2] != background){
if(!icon.HasKey(c[2])){
icon[c[2]] := {}
}
if(!icon[c[2]].HasKey(c[1])){
icon[c[2]][c[1]] := {"x" : [], "y" : []}
}
icon[c[2]][c[1]]["x"].Push(x)
icon[c[2]][c[1]]["y"].Push(ymax - y)
}
}
ToolTip, % (y < ymax ? y / ymax : 1) * 100 . "%"
}
Gdip_DisposeImage.Call(pBitmap)
Gdip_Shutdown.Call(pToken)
Group := SVGraph_Group("image")
for colour, list in icon {
for opacity, coords in list {
SVGraph_ScatterPlot(coords["x"], coords["y"], colour, size, opacity, False, Group)
}
}
ToolTip
} else {
MsgBox, Can't find Gdip.ahk in your Library.
}
locked := False
}
ARGBtoRGB(ARGB) {
ARGB := Format("0x{:08X}", ARGB)
Return [SubStr(ARGB, 1, 4) / 0xFF, Format("#{:06X}", "0x" SubStr(ARGB, 5))]
}
Get_Unique_Name(FileName, Directory := False){
SplitPath, FileName, , Dir, Ext, Name
if(!Directory){
Directory := InStr(Dir, ":") ? Dir : A_WorkingDir "\" Dir
}
if(SubStr(Directory, 0) != "\"){
Directory .= "\"
}
While Exist(Directory . Name . (index ? " (" . index . ")." : ".") . Ext) {
index := A_Index
}
Return Name . (index ? " (" . index . ")." : ".") . Ext
}
Exist(path){
IfExist, %path%
Return 1
Return 0
}