-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplottk_data.tcl
More file actions
73 lines (53 loc) · 2.12 KB
/
implottk_data.tcl
File metadata and controls
73 lines (53 loc) · 2.12 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
# Copyright (c) 2022 Nicolas ROBERT.
# Distributed under MIT license. Please see LICENSE for details.
namespace eval ::implottk {}
proc ::implottk::cbFuncPlot {data idx pPoint} {
# callback for implot::PlotLineG
#
# data - pointer (NULL)
# idx - index list coordinates
# pPoint - struct data {x y}
#
# Returns ImPlotPoint struct
try {
upvar 1 coords values ; # values is list in caller's context. Could be global also.
lassign [lindex $values $idx] x y; # Co-ords of idx'th point
cffi::pointer safe $pPoint;
implot::ImPlotPoint tonative $pPoint [list x $x y $y]
cffi::pointer dispose $pPoint
return $pPoint
} on error {result} {
return -code error $result
}
}
proc ::implottk::dataLine {num options} {
if {[dict exists $options -name]} {
set name [dict get $options -name]
} else {
set name $num
}
if {[dict exists $options -dataX] && ![dict exists $options -dataY]} {
error "'-dataY' key should be set when '-dataX' is present..."
}
if {![dict exists $options -dataX] && [dict exists $options -dataY]} {
error "'-dataX' key should be set when '-dataY' is present..."
}
if {[dict exists $options -dataX] && [dict exists $options -dataY]} {
set dataX [dict get $options -dataX]
set dataY [dict get $options -dataY]
if {[llength $dataX] != [llength $dataY]} {
error "length '-dataX' should be equal to length '-dataY'..."
}
set xs [implottk::doubleToPointer $dataX]
set ys [implottk::doubleToPointer $dataY]
set cmdplot [list implot::PlotLine_doublePtrdoublePtr $name $xs $ys [llength $dataX]]
}
if {[dict exists $options -data]} {
# not supported yet
error "not implanted... yet use -dataX -dataY flags"
set data [dict get $options -data]
if {[llength $data] != 2} {
}
}
return $cmdplot
}