Skip to content

Instantly share code, notes, and snippets.

@yyamasak
Created May 28, 2020 08:49
Show Gist options
  • Save yyamasak/7b9751437b2ea545ebe91b1167fd628b to your computer and use it in GitHub Desktop.
Save yyamasak/7b9751437b2ea545ebe91b1167fd628b to your computer and use it in GitHub Desktop.
console show
package require BLT
namespace import blt::*
set graph [graph .graph]
pack $graph -fill both -expand yes
set gindex "Element A"
set cl #ff5642
$graph pen create d$gindex -linewidth 0 -pixels 2 -color white -outline $cl -outlinewidth 3 -fill ""
$graph pen create dn$gindex -linewidth 0 -pixels 0 -color white
$graph pen create n$gindex -linewidth 0 -pixels 0 -color $cl -outline $cl -outlinewidth 2 -fill white
$graph pen create a$gindex -linewidth 1 -pixels 0 -color $cl
$graph element create d$gindex -label "" -pen dn$gindex -activepen d$gindex
$graph element create $gindex -pen n$gindex -activepen a$gindex
set xData {0.0 500.0 1500.0}
set yData {4010.0 30584.0 142953.0}
$graph element configure d$gindex \
-xdata $xData \
-ydata $yData \
-scalesymbols 0 \
-smooth linear
set x_list [list [lindex $xData 0] [lindex $xData end]]
set y_list [list [lindex $yData 0] [lindex $yData end]]
$graph element configure $gindex \
-xdata $x_list \
-ydata $y_list \
-scalesymbols 0 \
-smooth linear
$graph element activate $gindex
$graph element activate d$gindex
set elements [lsearch -all -inline -not [$graph element names] d*]
bind $graph <Motion> [list on_motion %W %x %y $elements]
proc on_motion {g x y elements} {
set hit 0
foreach element $elements {
set hit1 [$g element closest $x $y data $element]
if {$element ni {hl vl}} {
set hit2 [$g element closest $x $y data d$element]
} else {
set hit2 0
}
set hit [expr {$hit1 || $hit2}]
if {$hit} {
puts "hit element=$element"
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment