LinearGauge


Aim is to indicate the value of a random variable updating every second.



XAML


∇  xaml←LinearGaugeXAML
⍝ XAML for the LinearGauge example
 xaml←⊂'<Window'
 xaml,←⊂'    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"'
 xaml,←⊂'    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"'
 xaml,←⊂'    xmlns:sfg="clr-namespace:Syncfusion.Windows.Gauge;assembly=Syncfusion.Gauge.WPF"'
 xaml,←⊂'    SizeToContent="WidthandHeight" Name="gaugewindow">'
 xaml,←⊂'    <StackPanel>'
 xaml,←⊂'        <sfg:LinearGauge Height="100">'
 xaml,←⊂'           <sfg:LinearGauge.Scales>'
 xaml,←⊂'               <sfg:LinearScale'
 xaml,←⊂'                   Height="100" BorderWidth="3" '
 xaml,←⊂'                   Maximum="10" Minimum="0" MajorIntervalValue="1"'
 xaml,←⊂'                   BackgroundBrush="Transparent" BorderBrush="Transparent" '
 xaml,←⊂'                   ScaleDirection="CounterClockwise" ScaleBarSize="15">'
 xaml,←⊂'                   <sfg:LinearScale.Ticks>'
 xaml,←⊂'                       <sfg:LinearMarkTick TickHeight="10"'
 xaml,←⊂'                           DistanceFromScale="3" TickStyle="MajorTick" TickShape="Rectangle"'
 xaml,←⊂'                           TickWidth="2"/>'
 xaml,←⊂'                   </sfg:LinearScale.Ticks>'
 xaml,←⊂'                   <sfg:LinearScale.Pointers>'
 xaml,←⊂'                       <sfg:LinearBarPointer Name="lg_pointer" '
 xaml,←⊂'                           PointerWidth="10"'
 xaml,←⊂'                           />'
 xaml,←⊂'                   </sfg:LinearScale.Pointers>'
 xaml,←⊂'               </sfg:LinearScale>'
 xaml,←⊂'           </sfg:LinearGauge.Scales>'
 xaml,←⊂'        </sfg:LinearGauge>'
 xaml,←⊂'        <Button Name="btnStop" Content="Stop"/>'
 xaml,←⊂'    </StackPanel>'
 xaml,←⊂'</Window>'


The more rational among you may wonder about ScaleDirection="CounterClockwise" - it's there to get the indicator illuminating from the bottom up.  Leave it out (or ScaleDirection="Clockwise") and the bar illuminates from the top down.  I despair.

And while we're at it I also don't know why a TickWidth of 2 is wider than a PointerWidth of 10.  Life's too short...


Code


∇ LinearGauge;⎕IO;⎕ML;xaml;⎕USING
⍝ Simple LinearGauge example
 ⎕IO ⎕ML←0 3
 xaml←LinearGaugeXAML
 window←#.UTIL.WPF.LoadXaml xaml(⊂'SyncGauge')
 window_lg_pointer←window.FindName⊂'lg_pointer'
 window_btnStop←window.FindName⊂'btnStop'
 window_btnStop.onClick←'#.LinearGauge.LinearGaugeStop'
 ⎕USING←'System,mscorlib.dll' 'System.Windows.Threading,WindowsBase.dll' 'System.Windows.Media,presentationcore.dll'
 timer←⎕NEW DispatcherTimer
 timer.Interval←⎕NEW TimeSpan(0 0 1)
 timer.onTick←'#.LinearGauge.LinearTick'
 timer.Start
 window.Show


The hocus-pocus to define and start the Timer should really hide away inside another function.

∇ LinearTick w;⎕IO;⎕ML
⍝ Set LinearPointerValue at each timer increment
 ⎕IO ⎕ML←0 3
  window_lg_pointer.Value←?10


∇  LinearGaugeStop w;⎕IO;⎕ML
⍝ Stop the LinearGauge and close the window
 ⎕IO ⎕ML←0 3
  timer.Stop
  window.Close


Notice also the untidiness (in terms of global variables) which is endemic to WPF-based code, especially when using Show rather than ShowDialog.

The 'SyncGauge' argument to #.UTIL.LoadXAML has the effect of adding 'Syncfusion.Windows.Gauge,Syncfusion/4.5/Syncfusion.Gauge.WPF.dll' to the ⎕USING list of LoadXAML


Operation

#.LinearGauge.LinearGauge

Unresolved Issues

More control over appearance.