# -*- mode: tcl; indent-tabs-mode: nil -*- # ---------------------------------------------------------------------- # COMPONENT: xyresult - X/Y plot in a ResultSet # # This widget is an X/Y plot, meant to view line graphs produced # as output from the run of a Rappture tool. Use the "add" and # "delete" methods to control the data objects showing on the plot. # ====================================================================== # AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2012 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== package require Itk package require BLT option add *XyResult.width 3i widgetDefault option add *XyResult.height 3i widgetDefault option add *XyResult.gridColor #d9d9d9 widgetDefault option add *XyResult.activeColor blue widgetDefault option add *XyResult.dimColor gray widgetDefault option add *XyResult.controlBackground gray widgetDefault option add *XyResult.font \ -*-helvetica-medium-r-normal-*-12-* widgetDefault set autocolors { #0000cd #cd0000 #00cd00 #3a5fcd #cdcd00 #cd1076 #009acd #00c5cd #a2b5cd #7ac5cd #66cdaa #a2cd5a #cd9b9b #cdba96 #cd3333 #cd6600 #cd8c95 #cd00cd #9a32cd #6ca6cd #9ac0cd #9bcd9b #00cd66 #cdc673 #cdad00 #cd5555 #cd853f #cd7054 #cd5b45 #cd6889 #cd69c9 #551a8b } option add *XyResult.autoColors $autocolors widgetDefault option add *XyResult*Balloon*Entry.background white widgetDefault itcl::class Rappture::XyResult { inherit itk::Widget itk_option define -gridcolor gridColor GridColor "" itk_option define -activecolor activeColor ActiveColor "" itk_option define -dimcolor dimColor DimColor "" itk_option define -autocolors autoColors AutoColors "" constructor {args} { # defined below } destructor { # defined below } public method add {dataobj {settings ""}} public method get {} public method delete {args} public method scale {args} public method parameters {title args} { # do nothing } public method download {option args} protected method Rebuild {} protected method ResetLimits {} protected method Zoom {option args} protected method Hilite {state x y} protected method Axis {option args} protected method GetAxes {dataobj} protected method GetLineMarkerOptions { style } protected method GetTextMarkerOptions { style } protected method EnterMarker { g name x y text } protected method LeaveMarker { g name } private variable _dispatcher "" ;# dispatcher for !events private variable _dlist "" ;# list of dataobj objects private variable _dataobj2color ;# maps dataobj => plotting color private variable _dataobj2width ;# maps dataobj => line width private variable _dataobj2dashes ;# maps dataobj => BLT -dashes list private variable _dataobj2raise ;# maps dataobj => raise flag 0/1 private variable _dataobj2desc ;# maps dataobj => description of data private variable _dataobj2type ;# maps dataobj => type of graph element private variable _dataobj2barwidth ;# maps dataobj => type of graph element private variable _elem2dataobj ;# maps graph element => dataobj private variable _label2axis ;# maps axis label => axis ID private variable _limits ;# axis limits: x-min, x-max, etc. private variable _autoColorI 0 ;# index for next "-color auto" private variable _hilite ;# info for element currently highlighted private variable _axis ;# info for axis manipulations private variable _axisPopup ;# info for axis being edited in popup common _downloadPopup ;# download options from popup private variable _markers private variable _nextElement 0 private method FormatAxis { axis w value } private method GetFormattedValue { axis g value } private method BuildAxisPopup { popup } private method ShowAxisPopup { axis } private method SetAxis { setting } private method SetAxisRangeState { axis } } itk::usual XyResult { keep -background -foreground -cursor -font } itk::usual Panedwindow { keep -background -cursor } # ---------------------------------------------------------------------- # CONSTRUCTOR # ---------------------------------------------------------------------- itcl::body Rappture::XyResult::constructor {args} { Rappture::dispatcher _dispatcher $_dispatcher register !rebuild $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" array set _downloadPopup { format csv } option add hull.width hull.height pack propagate $itk_component(hull) no itk_component add main { Rappture::SidebarFrame $itk_interior.main } pack $itk_component(main) -expand yes -fill both set f [$itk_component(main) component controls] itk_component add reset { button $f.reset -borderwidth 1 -padx 1 -pady 1 \ -highlightthickness 0 \ -image [Rappture::icon reset-view] \ -command [itcl::code $this Zoom reset] } { usual ignore -borderwidth -highlightthickness } pack $itk_component(reset) -padx 4 -pady 2 -anchor e Rappture::Tooltip::for $itk_component(reset) \ "Reset the view to the default zoom level" set f [$itk_component(main) component frame] itk_component add plot { blt::graph $f.plot \ -highlightthickness 0 -plotpadx 0 -plotpady 4 \ -rightmargin 10 } { keep -background -foreground -cursor -font } pack $itk_component(plot) -expand yes -fill both $itk_component(plot) pen configure activeLine \ -symbol square -pixels 3 -linewidth 2 \ -outline black -fill red -color black # Add bindings so you can mouse over points to see values: # $itk_component(plot) element bind all \ [itcl::code $this Hilite at %x %y] $itk_component(plot) element bind all \ [itcl::code $this Hilite at %x %y] $itk_component(plot) element bind all \ [itcl::code $this Hilite off %x %y] $itk_component(plot) legend configure -hide yes # # Add legend for editing hidden/elements: # set inner [$itk_component(main) insert end \ -title "Legend" \ -icon [Rappture::icon wrench]] $inner configure -borderwidth 4 itk_component add legend { Rappture::XyLegend $inner.legend $itk_component(plot) } pack $itk_component(legend) -expand yes -fill both after idle [subst { update idletasks $itk_component(legend) reset }] # quick-and-dirty zoom functionality, for now... Blt_ZoomStack $itk_component(plot) eval itk_initialize $args set _hilite(elem) "" } # ---------------------------------------------------------------------- # DESTRUCTOR # ---------------------------------------------------------------------- itcl::body Rappture::XyResult::destructor {} { } # ---------------------------------------------------------------------- # USAGE: add ?? # # Clients use this to add a dataobj to the plot. The optional # are used to configure the plot. Allowed settings are -color, # -brightness, -width, -linestyle and -raise. # ---------------------------------------------------------------------- itcl::body Rappture::XyResult::add {dataobj {settings ""}} { array set params { -color auto -brightness 0 -width 1 -type "line" -barwidth 1 -raise 0 -linestyle solid -description "" -param "" } # Override the defaults with first the