-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraphMaker.livecodescript
More file actions
1312 lines (1143 loc) · 47.6 KB
/
GraphMaker.livecodescript
File metadata and controls
1312 lines (1143 loc) · 47.6 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
script "GraphMaker"
-- GraphMaker Library
-- make a graph / chart
constant kLibraryName = "GraphMaker"
constant kLibraryVersion = 0.2
local sADefaults, sAMarkers
local sAG -- array holding graph-related calculated values
local sCountG, sCountT
-- XRangeIncludes - list of x values to be included (overall, only shared)
-- XFit - round limits to multiple of this
-- YRangeIncludes, YFit - same for Y
-- YRightRangeIncludes, YRightFit - same for Y on right
-- ?? XTopRangeIncludes, XTopFit - same for Y on right
-- DataIncludesX - T/F to say if ALL datasets contain X values (otherwiae, count them)
-- - startvalue, step value (0,1 == True)
-- Title - a title
-- etc.
-- XGridInterval - gap (in data units) between vertical grid lines (i.e. for X valuea)
-- set to 0 (default) or no grid
-- ?? XGridMinor - number of minor grids per major grid
-- ?? set to 0 (default) for no minor grid
-- XTickInterval - same as XGridInterval, but for ticks.
-- 0 = no axis at all, empty = (default) axis but no tick
-- YGridInterval, YGridMinor, YTickInterval - as X
-- YRGridInterval, YRGridMinor, YRTickInterval - as X for right side
-- ?? XTGridInterval, XTGridMinor, XTTickInterval - as X for top side
-- backgroundcolor - colour for background
-- Hints .... TODO
-- Data -
-- each dataset has
-- name (currently not used)
-- YRaxis - TRUE means use the Right axis for scaling, etc.
-- allowColonDel - (default TRUE) replace ":" with CR (set FASLE if there are ':'s in labels )
-- values - lines of values, [X,]y1,y2,y3
----------------------------------------------------------------------
--| handler gmSetCustomMarker
--|
--| Summary: create a custom marker
--|
--| Format: gmSetCustomMarker pName, pPoints, pFilled
--|
--| Parameters: pName - name for this marker
--| pPoints - coords of the marker (t -> markersize)
--| pFilled - where the marker should be filled (default TRUE)
--|
--| Return: nothing
----------------------------------------------------------------------
on gmSetCustomMarker pName, pPoints, pFilled
if pFilled is empty then put TRUE into pFilled
if pName is among the keys of sAMarkers then
put empty into sAMarkers[pName]
end if
put pFilled into sAMarkers[pName]["filled"]
replace ":" with CR in pPoints
put pPoints into sAMarkers[pName]["points"]
-- if pLineSize is empty then put sADefaults["linesize"] into pLineSize
-- put pLineSize into sAMarkers[pName]["linesize"]
end gmSetCustomMarker
----------------------------------------------------------------------
--| handler gmMakeGraph
--|
--| Summary: make a graph / chart
--|
--| Format: gmMakeGraph(pGrpId, pArray)
--|
--| Parameters: pString
--|
--| Return: nothing very much !?!
----------------------------------------------------------------------
function gmMakeGraph pId, pAG
local temp
local tName, tID
set the lockscreen to TRUE
local tRect -- the rectangle of the (given) group
put the rect of pId into tRect
logInfo "rect = " && tRect && the number of controls of pID
_gmCreateDefaults
put empty into sAG
-- make ourselves a group to hold all our controls
put _gmCreateGraph(pID) into temp
put temp into pID
set the vis of pID to TRUE
set the rect of pID to tRect
set the lockLoc of pID to TRUE
-- temp variables to work out the range of data
-- these will be stored into the sAG array when we're done
local Xmin, Xmax, Ymin, Ymax, YRmin, YRmax
put empty into Xmin
put empty into Ymin
put empty into YRmin
local tX, tStart, tStep
_gmInsertXValues pAG, tX, tStart, tStep
-- repeat for each key K in pAG["data"]
repeat with K = 1 to the number of lines in the keys of pAG["data"]
put pAG["data"][K]["values"] into temp
if pAG["allowColonDel"] is FALSE OR pAG["data"][K]["allowColonDel"] is FALSE then
else
replace ":" with CR in temp
end if
if pAG["DataIncludesX"] then
put temp into sAG[K]["values"]
else
put tStart into tX
repeat for each line L in temp
put tX & COMMA & L & CR after sAG[K]["values"]
add tStep to tX
end repeat
end if
put firstOf(Xmin, item 1 of sAG[K]["values"]) into Xmin
if pAG["data"][K]["YRaxis"] then
put firstOf(YRmin, item 2 of line 1 of sAG[K]["values"]) into YRmin
else
put firstOf(Ymin, item 2 of line 1 of sAG[K]["values"]) into Ymin
end if
end repeat
put Xmin into Xmax
put Ymin into Ymax
put YRmin into YRmax
includeInRange Xmin, Xmax, pAG["XRangeIncludes"]
includeInRange Ymin, Ymax, pAG["YRangeIncludes"]
includeInRange YRmin, YRmax, pAG["YRRangeIncludes"]
-- TODO offset for non-zero Ymin !!!
-- Find Min / Max values
local Yminthis, Ymaxthis
repeat for each key K in sAG
if K is not a number then next repeat
if pAG["data"][K]["graphType"] ends with "labels" then next repeat
-- get its min, max Y values
put item 2 of line 1 of sAG[K]["values"] into Yminthis
put Yminthis into Ymaxthis
repeat for each line L in sAG[K]["values"]
put min(item 1 of L, Xmin) into Xmin
put max(item 1 of L, Xmax) into Xmax
repeat for each item II in item 2 to -1 of L
put min(II, Yminthis) into Yminthis
put max(II, Ymaxthis) into Ymaxthis
end repeat
end repeat
put Yminthis, Ymaxthis into sAG[K]["Yminmax"]
if pAG["data"][K]["YRaxis"] then
put min(Yminthis, YRmin) into YRmin
put max(Ymaxthis, YRmax) into YRmax
else
put min(Yminthis, Ymin) into Ymin
put max(Ymaxthis, Ymax) into Ymax
end if
end repeat
--
if pAG["XFit"] > 0 then
put pAG["XFit"] * (Xmin div pAG["XFit"]) into Xmin
put pAG["XFit"] * ceil(Xmax / pAG["XFit"]) into Xmax
end if
if pAG["data"][K]["YRaxis"] then
if pAG["YRightFit"] > 0 then
put pAG["YRightFit"] * (YRmin div pAG["YRightFit"]) into YRmin
put pAG["YRightFit"] * ceil(YRmax / pAG["YRightFit"]) into YRmax
end if
else
if pAG["YFit"] > 0 then
put pAG["YFit"] * (Ymin div pAG["YFit"]) into Ymin
put pAG["YFit"] * ceil(Ymax / pAG["YFit"]) into Ymax
end if
end if
if pAG["XUnit"] is empty then
if pAG["graphtype"] = "bar" then
put sADefaults["XUnit"] into sAG["XUnit"]
else
repeat with K = 1 to the number of lines in the keys of pAG["data"]
if pAG["data"][K]["Graphtype"] = "bar" then
put sADefaults["XUnit"] into sAG["XUnit"]
exit repeat
end if
end repeat
end if
else
put pAG["XUnit"] into sAG["XUnit"]
end if
subtract sAG["XUnit"] / 2 from Xmin
add sAG["XUnit"] / 2 to Xmax
logInfo "min/max X" && Xmin && Xmax && "Y" && Ymin && YMax && "YRight" && YRmin && YRMax
-- set up the drawing area co-ords
-- will account for legend, title, labels on axes, etc.
local tGraphRect -- rectangle for actual drawing
put item 1 of tRect+10, item 2 of tRect+10, item 3 of tRect-10, item 4 of tRect-10 into tGraphRect
add pAG["Lmargin"] to item 1 of tGraphRect
add pAG["Tmargin"] to item 2 of tGraphRect
subtract pAG["Rmargin"] from item 3 of tGraphRect
subtract pAG["Bmargin"] from item 4 of tGraphRect
put makeTitles (pID, pAG, tGraphRect) into temp
put temp into tGraphRect
-- pID, pLabelName, pNum, pPosition, pFormatFunction
if pAG["YTickLabelSpacing"] <> 0 then
put findSpaceForAxisLabels(pID, "YaxisLabel", Ymax, 6, pAG["YAxisLabelFormat"], \
pAG["YTickLabelRotation"]) into temp
add item 1 of temp to item 1 of tGraphRect
end if
if pAG["YRTickLabelSpacing"] <> 0 AND \
(YRmin <> YRmax) then
put findSpaceForAxisLabels(pID, "YRaxisLabel", Ymax, 8, pAG["YRAxisLabelFormat"], \
pAG["YRTickLabelRotation"]) into temp
subtract item 1 of temp from item 3 of tGraphRect
end if
if pAG["XTickLabelSpacing"] < 0 OR pAG["XTickLabelSpacing"] > 0 OR pAG["XTickLabelSpacing"] is empty then
put findSpaceForAxisLabels(pID, "XaxisLabel", Xmax, 5, pAG["XAxisLabelFormat"], \
pAG["XAxisLabelRotation"]) into temp
subtract item 2 of temp from item 4 of tGraphRect
end if
-- base of actual drawing area
put item 1 of tGraphRect into sAG["XBase"]
put item 4 of tGraphRect into sAG["YBase"]
put item 4 of tGraphRect into sAG["YRBase"]
put Xmin into sAG["Xmin"]
put Xmax into sAG["Xmax"]
put Ymin into sAG["Ymin"]
put Ymax into sAG["Ymax"]
put YRmin into sAG["YRmin"]
put YRmax into sAG["YRmax"]
-- set up scaling
local t1, t2
put (item 3 of tGraphRect-10) - (item 1 of tGraphRect+10) into t1
put (Xmax - Xmin) into t2
if t2 <> 0 then put t1 / t2 into sAG["XS"]
put (item 4 of tGraphRect-10) - (item 2 of tGraphRect+10) into t1
put (Ymax - Ymin) into t2
if t2 <> 0 then put t1 / t2 into sAG["YS"]
put (YRmax - YRmin) into t2
if t2 <> 0 then put t1 / t2 into sAG["YRS"]
-- put _scalexy(Xmin, YMin) into temp
-- put _scalexy(Xmax, YMax) into temp
makeXAxis pID, pAG
makeYAxis pID, pAG
if YRmin <> YRmax then makeYRAxis pID, pAG
local tGraphType
local tPoints
repeat with K = 1 to the number of lines in the keys of pAG["data"]
put firstOf(pAG["data"][K]["graphtype"], pAG["graphtype"], "line") into tGraphType
switch tGraphType
case "scatter"
put TRUE into pAG["data"][K]["invisible"]
put firstOf(pAG["data"][K]["marker"], "star") into pAG["data"][K]["marker"]
-- and fall through - it's now just any old line chart
-- simple line graph
case "line"
case "step"
local tFilled
put firstOf(pAG["data"][K]["Filled"], pAG["Filled"], "line") into tFilled
put _scaledataset(sAG[K]["values"], pAG["data"][K]["YRAxis"]) into sAG[K]["XY"]
put empty into tPoints
repeat with i = 2 to the number of items in line 1 of sAG[K]["XY"]
put _gmCreategrc(K & "_" & I, pID) into tName
repeat for each line L in sAG[K]["XY"]
if pAG["data"][K]["graphtype"] = "step" then
local tHorizontalFirst
put firstOf(pAG["data"][K]["HorizontalFirst"], pAG["HorizontalFirst"]) into tHorizontalFirst
if tPoints is empty then
put item 1 of l & comma & item i of L &CR after tPoints
else
if tHorizontalFirst then
put item 1 of L & comma & item i of line -1 of tPoints &CR after tPoints
put item 1 of L & comma & item i of L &CR after tPoints
else
put item 1 of line -1 of tPoints & comma & item i of L &CR after tPoints
put item 1 of l & comma & item i of L &CR after tPoints
end if
end if
else
put item 1 of l & comma & item i of L &CR after tPoints
if pAG["data"][K]["invisible"] then put CR after tPoints
end if
end repeat
local tLineNumber, t
put i-1 into tLineNumber
if tFilled then
put _gmGetColor(pAG, "fillcolor", K, i-2) into temp
set the backgroundColor of tName to temp
set the opaque of tName to TRUE
local tXO, tYO
put _scalexy(0,0) into temp
put item 1 of temp into tXO
put item 2 of temp into tYO
put item 1 of line -1 of tPoints & COMMA & \-- X of last point
tYO & CR \
after tPoints
put item 1 of line 1 of tPoints & COMMA & \-- X of last point
tYO & CR \
after tPoints
put item 1 of line 1 of tPoints & COMMA & \-- X of first point
item i of line 1 of tPoints &CR \ -- Y of first point
after tPoints
end if
set the points of tName to tPoints
set the style of tName to "polygon" -- NOT line - we need markers
put _gmGetColor(pAG, "color", K, i-2) into temp
set the foregroundColor of tName to temp
put firstOf(pAG["data"][K]["lineSize"], pAG["lineSize"], sADefaults["linesize"]) into temp
put max(tLineNumber, the number of lines in temp) into t
set the lineSize of tName to line t of temp
put firstOf(pAG["data"][K]["blendLevel"], pAG["blendLevel"], 30) into temp
set the blendLevel of tName to temp
switch
case pAG["data"][K]["dashed"] is true
put sADefaults["dashed"] into temp
break
case pAG["data"][K]["dotted"] is true
put sADefaults["dotted"] into temp
break
case pAG["data"][K]["dotdashed"] is true
put sADefaults["dotdashed"] into temp
break
case pAG["data"][K]["dotdashed"] is not empty
put pAG["data"][K]["dotdashed"] into temp
break
case pAG["data"][K]["dotted"] is not empty
put pAG["data"][K]["dotted"] into temp
break
case pAG["data"][K]["dashed"] is not empty
put pAG["data"][K]["dashed"] into temp
break
default
put empty into temp
end switch
if temp is not empty then
set the dashes of tName to temp
end if
local tA
if pAG["data"][K]["dropshadow"] is not empty then
put sADefaults["dropShadow"] into tA
if not pAG["data"][K]["dropshadow"] then
repeat for each line L in pAG["data"][K]["dropshadow"]
put item 2 to -1 of L into tA[item 1 of L]
end repeat
end if
set the dropshadow of tName to tA
end if
-- markers
local tMarkerName
if pAG["data"][K]["marker"] is not empty then
put pAG["data"][K]["marker"] into tMarkerName
if tMarkerName is not among the keys of sAMarkers then
put "square" into tMarkerName
end if
put expandMarker(tMarkerName, firstOf(pAG["data"][K]["markersize"], 5)) into temp
-- put sAMarkers[tMarkerName]["points"] into temp
-- replace "t" with firstOf(pAG["data"][K]["markersize"], 5) in temp
set the markerpoints of tName to temp
set the markerlinesize of tName to 2 -- TODO?? sAMarkers[tMarkerName]["linesize"]
set the markerfilled of tName to sAMarkers[tMarkerName]["filled"]
put _gmGetColor(pAG, "markercolor", K, i-2) into temp
if temp is empty then
put sAMarkers[tMarkerName]["color"] into temp
end if
set the bordercolor of tName to temp
set the hilitecolor of tName to temp
set the markerdrawn of tName to TRUE
end if
-- set the dashes of tName to sAG["dashed"]
set the vis of tName to TRUE
end repeat
break
case "bar"
put _scaledataset(sAG[K]["values"], pAG["data"][K]["YRAxis"]) into sAG[K]["XY"]
put empty into tPoints
local tAName
repeat with i = 2 to the number of items in line 1 of sAG[K]["XY"]
put _gmCreategrc(K & "_" & I, pID) into tAName[i]
end repeat
local tAPts, tBase
repeat for each line L in sAG[K]["XY"]
repeat with i = 2 to the number of items in line 1 of sAG[K]["XY"]
if i = 2 then
put _scalexy(sAG["Xmin"], sAG["Ymin"]) into temp
put item 2 of temp into tBase
else
put item -1 of tAPts[i-1] into tBase
end if
put CR after tAPts[i]
put item 1 of L & comma & tBase &CR & \
item 1 of L & comma & item i of L &CR after tAPts[i]
if line -2 of tAPts[i] is empty then
delete line -2 of tAPts[i]
end if
-- put item 1 of L & comma & tBase &CR after tAPts[i]
-- put item 1 of L & comma & item i of L &CR after tAPts[i]
-- logInfo i && ":" && the number of lines in tAPts[i]
end repeat
end repeat
repeat with i = 2 to the number of items in line 1 of sAG[K]["XY"]
set the points of tAName[i] to tAPts[i]
set the style of tAName[i] to "line"
put _gmGetColor(pAG, "color", K, i-2) into temp
set the foregroundColor of tAName[i] to temp
put firstOf(pAG["barDensity"], sADefaults["barDensity"]) into t
put sAG["XUnit"] * sAG["XS"] * t / 100 into temp
set the lineSize of tAName[i] to temp
set the capStyle of tAName[i] to "butt"
set the vis of tAName[i] to TRUE
end repeat
break
local tString
case "XTickLabels"
local tY
repeat for each line L in sAG[K]["values"]
put _scalexy(item 1 of L, sAG["YMin"]) into temp
put item 1 of temp into tX
put item 2 of temp into tY
-- NB do not format - this graphtype already has explicit labels
-- put formatLabel(item 2 of L, pAG["XAxisLabelFormat"]) into tString
put formatLabel(item 2 of L, empty) into tString
_gmMakeXLabel pID, pAG, tString, item 1 of temp, item 2 of temp, K, i-2
-- put _gmCreateText(pID, tString, tX, tY,\
-- 5, FALSE, \
-- empty, \ -- the name for this control
-- empty, \ -- the text info for it
-- "XAxisLabel") \-- the name for any default settings
-- into temp
-- put item 1 of temp into tName
-- put _gmGetColor(pAG, "color", K, i-2) into temp
-- set the foregroundColor of tName to temp
-- set the vis of tName to TRUE
end repeat
break
case "YTickLabels"
repeat for each line L in sAG[K]["values"]
put _scalexy(sAG["XMin"], item 2 of L) into temp
put item 1 of temp into tX
put item 2 of temp into tY
-- NB do not format - this graphtype already has explicit labels
-- put formatLabel(item 3 of L, pAG["YAxisLabelFormat"]) into tString
put formatLabel(item 3 of L, empty) into tString
put _gmCreateText(pID, tString, tX, tY,\
6, FALSE, \
empty, \ -- the name for this control
empty, \ -- the text info for it
"YAxisLabel") \-- the name for any default settings
into temp
put item 1 of temp into tName
put _gmGetColor(pAG, "color", K, i-2) into temp
set the foregroundColor of tName to temp
set the vis of tName to TRUE
end repeat
break
end switch
end repeat
put empty into t1
set the lockscreen to FALSE
end gmMakeGraph
-- not normally user-called, but can be in odd cases
on _gmCreateDefaults
local temp
put "20,20" into sADefaults["dashed"]
put "2,10" into sADefaults["dotted"]
put "12,8,2,8" into sADefaults["dotdashed"]
local tDropShadow
put "255,0,0" into tDropShadow["color"]
put "normal" into tDropShadow["blendmode"]
put 255 into tDropShadow["opacity"]
put "box1pass" into tDropShadow["filter"]
put 6 into tDropShadow["size"]
put 100 into tDropShadow["spread"]
put 3 into tDropShadow["distance"]
put 45 into tDropShadow["angle"]
put tDropShadow into sADefaults["dropshadow"]
put 1 into sADefaults["hints"]["YtickInterval"]["Guess"]
put 20 into sADefaults["hints"]["YtickInterval"]["min"]
put 200 into sADefaults["hints"]["YtickInterval"]["max"]
put 5 into sADefaults["hints"]["YtickInterval"]["mult"]
put sADefaults["hints"]["YtickInterval"] into sADefaults["hints"]["XtickInterval"]
put sADefaults["hints"]["YtickInterval"] into sADefaults["hints"]["YRtickInterval"]
put 1 into sADefaults["hints"]["YTickLabelSpacing"]["Guess"]
put 100 into sADefaults["hints"]["YTickLabelSpacing"]["min"]
put 500 into sADefaults["hints"]["YTickLabelSpacing"]["max"]
put 2.5 into sADefaults["hints"]["YTickLabelSpacing"]["mult"]
put 140 into sADefaults["hints"]["YTickLabelSpacing"]["Target"]
put sADefaults["hints"]["YTickLabelSpacing"] into sADefaults["hints"]["XTickLabelSpacing"]
put sADefaults["hints"]["YTickLabelSpacing"] into sADefaults["hints"]["YRTickLabelSpacing"]
put 2 into sADefaults["linesize"]
put "255,0,0:0,255,0:0,0,255:255,255,0:255,0,255:0,255,255:200,200,200" into temp
replace ":" with CR in temp
put temp into sADefaults["colors"]
replace 255 with 128 in temp
replace 200 with 100 in temp
put temp into sADefaults["fillcolors"]
put "0,255,0:0,0,255:255,255,0:255,0,255:0,255,255:200,200,200:255,0,0" into temp
replace ":" with CR in temp
put temp into sADefaults["markercolors"]
replace 255 with 128 in temp
replace 200 with 100 in temp
put temp into sADefaults["markerfillcolors"]
-- put empty into sAMarkers -- Don't empty it, just redefine the ones we need
gmSetCustomMarker "square", \
"-t,-t:-t,t:t,t:t,-t"
gmSetCustomMarker "star", \
"-t,-t:t,t::-t,t:t,-t", FALSE
gmSetCustomMarker "diamond", \
"0,t:t,0:0,-t:-t,0"
gmSetCustomMarker "triangle", \
"-t,t:t,t:0,-t"
put 5 into sADefaults["markersize"]
-- TextStyle is color CR Size CR Style CR Name
put "color,0,0,0:textsize,24:textstyle,bold" into temp
split temp by ":" and COMMA
put temp into sADefaults["TitleTextInfo"]
put "color,0,0,0:size,18" into temp
split temp by ":" and COMMA
put temp into sADefaults["XTitleTextInfo"]
put temp into sADefaults["YTitleTextInfo"]
put temp into sADefaults["YRTitleTextInfo"]
put "color,0,0,0:size,12" into temp
split temp by ":" and COMMA
put temp into sADefaults["LabelTextInfo"]
put 1 into sADefaults["XUnit"]
put 75 into sADefaults["barDensity"]
end _gmCreateDefaults
-- private handlers for internal use
command makeYAxis pID, pAG
local tPoints
-- draw a Y axis, if needed
if pAG["YTickInterval"] = 0 then
exit makeYAxis
end if
local tName
put _gmCreateGRC("Y_Axis", pID) into tName
set the style of tName to "line"
put _scalexy(sAG["Xmin"], sAG["Ymin"]) &CR into tPoints
put _scalexy(sAG["Xmin"], sAG["Ymax"]) &CR after tPoints
adaptTickSettings pAG, "YTick", sAG["YS"], sAG["Ymax"]-sAG["Ymin"]
local temp
if sAG["YTickInterval"] > 0 then
local tBase, tY
put sAG["YTickInterval"] * (sAG["Ymin"] div sAG["YTickInterval"]) into tBase
repeat with i = tBase to sAG["Ymax"] step sAG["YTickInterval"]
if i > sAG["Ymax"] then
-- logInfo "exiting repeat" && i && Ymax
exit repeat
end if
put i into tY
if tY < sAG["Ymin"] then put sAG["Ymin"] into tY
put CR after tPoints
put _scalexy(sAG["Xmin"], tY) into temp
put temp & CR after tPoints
add 10 to item 1 of temp
put temp & CR after tPoints
-- logInfo "Y tick" && sAG["Xmin"] && i && sAG["YTickInterval"] && line -1 of tPoints
end repeat
end if
if sAG["YTickLabelspacing"] > 0 then
repeat with i = tBase to sAG["Ymax"] step sAG["YTickLabelspacing"] * sAG["YTickInterval"]
if i > sAG["Ymax"] then
-- logInfo "exiting repeat" && i && Ymax
exit repeat
end if
put i into tY
if tY < sAG["Ymin"] then put sAG["Ymin"] into tY
put _scalexy(sAG["Xmin"], tY) into temp
put formatLabel(tY, pAG["YAxisLabelFormat"]) into tY
put _gmCreateText(pID, tY, item 1 of temp, item 2 of temp,\
6, FALSE, \
empty, \ -- the name for this control
empty, \ -- the text info for it
"YAxisLabel") \-- the name for any default settings
into temp
-- logInfo "Y label" && temp && sAG["YTickLabelspacing"] && line -1 of tPoints
local tt
put item 1 of temp into tt
set the vis of tt to TRUE
end repeat
end if
if sAG["YGridInterval"] > 0 then
repeat with i = tBase to sAG["Ymax"] step sAG["YGridInterval"] * sAG["YTickInterval"]
if i > sAG["Ymax"] then
exit repeat
end if
put i into tY
if tY < sAG["Ymin"] then put sAG["Ymin"] into tY
put CR after tPoints
put _scalexy(sAG["Xmin"], tY) & CR after tPoints
put _scalexy(sAG["Xmax"], tY) & CR after tPoints
end repeat
end if
set the points of tName to tPoints
set the vis of tName to TRUE
end makeYAxis
command makeYRAxis pID, pAG
local tPoints
-- draw a YR axis, if needed
if pAG["YRTickInterval"] = 0 then
exit makeYRAxis
end if
local tName
put _gmCreateGRC("YR_Axis", pID) into tName
set the style of tName to "line"
put _scalexy(sAG["Xmax"], sAG["YRmin"], TRUE) &CR into tPoints
put _scalexy(sAG["Xmax"], sAG["YRmax"], TRUE) &CR after tPoints
adaptTickSettings pAG, "YRTick", sAG["YRS"], sAG["YRmax"]-sAG["YRmin"]
local temp
if sAG["YRTickInterval"] > 0 then
local tBase, tY
put sAG["YRTickInterval"] * (sAG["YRmin"] div sAG["YRTickInterval"]) into tBase
repeat with i = tBase to sAG["YRmax"] step sAG["YRTickInterval"]
if i > sAG["YRmax"] then
-- logInfo "exiting repeat" && i && Ymax
exit repeat
end if
put i into tY
if tY < sAG["YRmin"] then put sAG["YRmin"] into tY
put CR after tPoints
put _scalexy(sAG["Xmax"], tY, TRUE) into temp
put temp & CR after tPoints
subtract 10 from item 1 of temp
put temp & CR after tPoints
-- logInfo "Y tick" && sAG["Xmin"] && i && sAG["YTickInterval"] && line -1 of tPoints
end repeat
end if
if sAG["YRTickLabelspacing"] > 0 then
repeat with i = tBase to sAG["YRmax"] step sAG["YRTickLabelspacing"] * sAG["YRTickInterval"]
if i > sAG["YRmax"] then
-- logInfo "exiting repeat" && i && Ymax
exit repeat
end if
put i into tY
if tY < sAG["YRmin"] then put sAG["YRmin"] into tY
put _scalexy(sAG["Xmax"], tY, TRUE) into temp
put formatLabel(tY, pAG["YRAxisLabelFormat"]) into tY
put _gmCreateText(pID, tY, item 1 of temp, item 2 of temp,\
8, FALSE, \
empty, \ -- the name for this control
empty, \ -- the text info for it
"YRAxisLabel") \-- the name for any default settings
into temp
-- logInfo "Y label" && temp && sAG["YTickLabelspacing"] && line -1 of tPoints
local tt
put item 1 of temp into tt
set the vis of tt to TRUE
end repeat
end if
if sAG["YRGridInterval"] > 0 then
repeat with i = tBase to sAG["YRmax"] step sAG["YRGridInterval"] * sAG["YRTickInterval"]
if i > sAG["YRmax"] then
exit repeat
end if
put i into tY
if tY < sAG["YRmin"] then put sAG["YRmin"] into tY
put CR after tPoints
put _scalexy(sAG["Xmin"], tY, TRUE) & CR after tPoints
put _scalexy(sAG["Xmax"], tY, TRUE) & CR after tPoints
end repeat
end if
set the points of tName to tPoints
set the vis of tName to TRUE
end makeYRAxis
-- private handlers for internal use
command makeXAxis pID, pAG
local tPoints
-- draw an X axis, if needed
if pAG["XTickInterval"] < 0 then
exit makeXAxis
end if
local tName
put _gmCreateGRC("X_Axis", pID) into tName
set the style of tName to "line"
put _scalexy(sAG["Xmin"], sAG["Ymin"]) &CR into tPoints
put _scalexy(sAG["Xmax"], sAG["Ymin"]) &CR after tPoints
adaptTickSettings pAG, "XTick", sAG["XS"], sAG["Xmax"]-sAG["Xmin"]
local temp, tBase, tX
if sAG["XTickInterval"] > 0 then
put sAG["XTickInterval"] * (sAG["Xmin"] div sAG["XTickInterval"]) into tBase
repeat with i = tBase to sAG["Xmax"] step sAG["XTickInterval"]
if i > sAG["Xmax"] then
-- logInfo "exiting repeat" && i && Ymax
exit repeat
end if
put i into tX
if tX < sAG["Xmin"] then put sAG["Xmin"] into tX
put CR after tPoints
put _scalexy(tX, sAG["Ymin"]) into temp
put temp & CR after tPoints
add -10 to item 2 of temp
put temp & CR after tPoints
end repeat
end if
set the points of tName to tPoints
set the vis of tName to TRUE
if sAG["XTickLabelspacing"] > 0 then
repeat with i = tBase to sAG["Xmax"] step sAG["XTickLabelspacing"] * sAG["XTickInterval"]
put i into tX
if i > sAG["Xmax"] - sAG["XTickInterval"] then
if pAG["XAxisLabelForceRightAxisLabel"] then
put sAG["Xmax"] into tX
else
exit repeat
end if
end if
local tText
if tX < sAG["Xmin"] then put sAG["Xmin"] into tX
put _scalexy(tX, sAG["Ymin"]) into temp
put formatLabel(tX, pAG["XAxisLabelFormat"]) into tText
_gmMakeXLabel pID, pAG, tText, item 1 of temp, item 2 of temp
if i > sAG["Xmax"] then exit repeat
end repeat
end if
if sAG["XGridInterval"] > 0 then
repeat with i = tBase to sAG["Xmax"] step sAG["XGridInterval"] * sAG["XTickInterval"]
if i > sAG["Xmax"] then
exit repeat
end if
put i into tX
if tX < sAG["Xmin"] then put sAG["Xmin"] into tX
put CR after tPoints
put _scalexy(tX, sAG["Ymin"]) & CR after tPoints
put _scalexy(tX, sAG["Ymax"]) & CR after tPoints
end repeat
end if
set the points of tName to tPoints
set the vis of tName to TRUE
end makeXAxis
on _gmMakeXLabel pID, pAG, pText, pX, pY, pColorNumber, pColorOffset
local temp, tColor
put _gmCreateText(pID, pText, pX, pY,\
5, FALSE, \
empty, \ -- the name for this control
empty, \ -- the text info for it
"XAxisLabel") \-- the name for any default settings
into temp
-- put "after" && the loc of (item 1 of temp) &CR after msg
put _gmGetColor(pAG, "color", pColorNumber, pColorOffset) into tColor
set the foregroundColor of (item 1 of temp) to tColor
if pAG["XAxisLabelRotation"] is empty OR pAG["XAxisLabelRotation"] = 0 then
set the vis of (item 1 of temp) to TRUE
else
local tXY, tWidth, tHeight
put the loc of (item 1 of temp) into tXY
-- so calculate new loc by subtracting half height and adding half width
put item 2 of temp into tWidth
put item 3 of temp into tHeight
get _gmTurnTextIntoGraphic(pID, item 1 of temp, word 2 of item 1 of temp, \
item 1 of tXY, item 2 of tXY - tHeight / 2 + tWidth / 2, 90)
end if
end _gmMakeXLabel
on _gmInsertXValues pAG, @pX, @pStart, @pStep
switch pAG["DataIncludesX"]
case TRUE
break
case empty
put 0 into pStart
put 1 into pStep
break
default
if item 1 of pAG["DataIncludesX"] is a number then
put item 1 of pAG["DataIncludesX"] into pX
if item 2 of pAG["DataIncludesX"] is a number then
put item 1 of pAG["DataIncludesX"] into pStep
else
put 1 into pStep
end if
else
put 0 into pStart
put 1 into pStep
end if
if pStep = 0 then
put 1 into pStep
end if
break
end switch
end _gmInsertXValues
----------------------------------------------------------------------
--| handler _gmCreateGraph
--|
--| Summary: re-create the controls for a graph (i.e. can be called once only)
--|
--| Format: _gmCreateGraph(pGrpId)
--|
--| Parameters: pGrpID - long id of the group to contain the controls
--|
--| Return: the long ID of the created group
----------------------------------------------------------------------
function _gmCreateGraph pId
logInfo "pID = " && pID
local temp, tName
if there is a grp "GraphGroup" of pID then
delete grp "GraphGroup" of pID
end if
create invisible grp "GraphGroup" in pID
put the long ID of grp "GraphGroup" of pID into pID
put 0 into sCountG -- counts of Grapchics, Ttiles, etc.
put 0 into sCountT
return pID
end _gmCreateGraph
private function _scaledataset pData, pRAxis
local temp, t
repeat for each line L in pData
put sAG["Xbase"] + sAG["XS"] * (item 1 of L - sAG["Xmin"]) after temp
repeat for each item II in item 2 to -1 of L
put II into t
put comma after temp
if pRAxis is empty then
put sAG["Ybase"] - sAG["YS"] * (II - sAG["Ymin"]) after temp
else
put sAG["YRbase"] - sAG["YRS"] * (II - sAG["YRmin"]) after temp
end if
end repeat
put CR after temp
end repeat
return temp
end _scaledataset
private function _scalexy px, py, pRAxis
local temp
put sAG["Xbase"] + sAG["XS"] * (px - sAG["Xmin"]) into temp
put comma after temp
if pRAxis is empty then
put sAG["Ybase"] - sAG["YS"] * (py - sAG["Ymin"]) after temp
else
put sAG["Ybase"] - sAG["YRS"] * (py - sAG["YRmin"]) after temp
end if
return temp
end _scalexy
private function _gmCreateGRC pName, pID
local tName
create invisible graphic ("G_" & pName) in pID
put "grc " & q("G_" & pName) & " of " & pID into tName
return tName
end _gmCreateGRC
function _gmCreateText pID, pText, pX, pY, pPosition, pRot, pName, pTextInfo, pTextName
-- pPosition is 1...4 corner TL, TR, BT=R, BL
-- 5...8 mid-line T,R,B,L
-- 0/empty centre
if pPosition is empty then put 0 into pPosition
replace ":" with CR in pTextInfo
local tName
if pName is empty then
put "T_" & sCountT into pName
add 1 to sCountT
end if
create invisible fld (pName) in pID
put "fld " & q(pName) & " of " & pID into tName
set the showborder of tName to FALSE
set the opaque of tName to FALSE
-- TextStyle is color CR Size CR Style CR Name
local temp, tADefaultTextInfo
put sADefaults[pTextName & "TextInfo"] into tADefaultTextInfo
replace ":" with CR in pTextInfo
split pTextInfo by CR and COMMA
put combineArrays(pTextInfo, tADefaultTextInfo) into pTextInfo
put pTextInfo["color"] into temp
if temp is not empty then
set the foregroundcolor of tName to temp
end if
put pTextInfo["textsize"] into temp
if temp is not empty then
set the textsize of tName to temp
end if
put pTextInfo["textstyle"] into temp
if temp is not empty then
set the textStyle of tName to temp
end if
put pTextInfo["textfont"] into temp
if temp is not empty then
set the textfont of tName to temp
end if