Changeset 738


Ignore:
Timestamp:
Oct 17, 2009, 5:20:47 PM (12 years ago)
Author:
Arno Wacker
Message:
  • Fixed autozoom feature of frequency test; finally seems to work in all cases - this closes #97, after all it was not an editor bug, but a missing "Stretch" in the FrequencyTest-presentation.
  • Removed the zoom-slider from presentation. Zoom/Scale is now accessible only in the settings (usually not needed, since autozoom is default)
  • Re-introduced ProgressChanged (faked, it just become fully green when done)
  • Changed Background to LightYellow in Run-mode and LightGray when stopped. This way it does not interfere with the progress-green.
  • Updated samples using FrequencyTest to avoid loading warnings.
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/FrequencyTest/CollectionElement.cs

    r700 r738  
    88    public class CollectionElement
    99    {
    10         private string m_caption;
    11         private double m_percent;
    12         private int m_amount;
     10        private string caption;
     11        private double normalizedValue;
     12        private double absoluteValue;
    1313
    14         public CollectionElement(int amount, double percent, string caption)
     14        public CollectionElement(double absoluteVal, double normalizedVal, string caption)
    1515        {
    16             m_amount = amount;
    17             m_caption = caption;
    18             m_percent = percent;
     16            this.absoluteValue = absoluteVal;
     17            this.caption = caption;
     18            this.normalizedValue = normalizedVal;
    1919        }
    2020
    21 
     21        /// <summary>
     22        /// The caption to appear under the bar
     23        /// </summary>
    2224        public string Caption
    2325        {
    24             get { return m_caption; }
     26            get { return caption; }
    2527            set
    2628            {
    27                 m_caption = value;
     29                caption = value;
    2830            }
    2931        }
    3032
    31 
     33        /// <summary>
     34        /// The value to be written on top of the bar, usually the percentage value
     35        /// </summary>
    3236        public double Percent
    3337        {
    34             get { return m_percent; }
     38            get { return normalizedValue; }
    3539            set
    3640            {
    37                 m_percent = value;
     41                normalizedValue = value;
    3842            }
    3943        }
    4044
    41 
    42         public int Amount
     45        /// <summary>
     46        /// The absolute value, used for the absolute heigth of the bar
     47        /// </summary>
     48        public double Amount
    4349        {
    44             get { return m_amount; }
     50            get { return absoluteValue; }
    4551            set
    4652            {
    47                 m_amount = value;
     53                absoluteValue = value;
    4854            }
    4955        }
  • trunk/CrypPlugins/FrequencyTest/FrequencyTest.cs

    r737 r738  
    88using Cryptool.PluginBase.Analysis;
    99using Cryptool.PluginBase.Miscellaneous;
     10using System.Windows.Media;
    1011
    1112namespace Cryptool.FrequencyTest
     
    3233        private IDictionary<string, double[]> grams = new SortedDictionary<string, double[]>();
    3334        private DataSource data = new DataSource();
    34         private double presentationScaler = 1.0; // the slider-value
    35         private double presentationOffset = 60.0; // top-offest in presentation, must skip height of headline-text
     35        private double presentationScaler = 1.0; // the initial zoom value
     36        private double presentationBarWidth = 24.7; // the width in pixel of a single chart bar
     37        private double presentationBarHeightAdd = 8.0 + 2.0 * 26.0; // the additional heigth to a chart bar, comprised of two rectangles (3px, 5px) and two textblocks
    3638
    3739        // TODO: this shall be an algorithm setting or an optional word
     
    147149            }
    148150
     151            presentation.SetBackground(Brushes.LightYellow);
     152
    149153            string workstring = stringInput;
    150154
     
    195199                updatePresentation();
    196200            }
     201
     202            // Show progress finished.
     203            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(1.0, 1.0));
    197204
    198205            OnPropertyChanged("StringOutput");
     
    236243        private void updatePresentation()
    237244        {
    238             if (grams.Count > 0 && presentation.chart.ActualWidth > 0)
    239             {
     245            if (grams.Count > 0 && presentation.ActualWidth > 0)
     246            {
     247                // retrieve the maximum value from all grams
    240248                double max = grams.Values.Max(item => item[PERCENTAGED]);
    241249                GuiLogMessage("Max n-gram percentage is: " + max, NotificationLevel.Debug);
    242250
     251                // calculate the needed width for the chart (unscaled) in pixel
     252                double unscaledChartWidth = (double)grams.Count * presentationBarWidth;
     253
     254                // retrieve the maximum bar height from settings in pixel
     255                double maxBarHeight = (double) settings.ChartHeight;
     256
     257
     258                if (settings.Autozoom)
     259                {
     260                    // calculate the scaling-value depeding on the needed width ad the current presetnation width
     261                    presentationScaler = presentation.ActualWidth / unscaledChartWidth;
     262                    settings.Scale = (int)(presentationScaler * 10000.0);
     263
     264                    //set the maximum bar height to the current heigth of chart-area in presentation (best fill)
     265                    //maxBarHeight = presentation.chartBars.ActualHeight - presentationBarHeightAdd;
     266                    maxBarHeight = (presentation.ActualHeight / presentationScaler) - (presentation.chartHeadline.ActualHeight + presentationBarHeightAdd);
     267                }
     268
     269                // remove all entries
    243270                data.ValueCollection.Clear();
    244                 double chartheight = (double) settings.ChartHeight;
    245                 if (settings.Autozoom)
    246                 {
    247                     chartheight = presentation.ActualHeight - presentation.sli.ActualHeight - (presentation.chartHeadline.ActualHeight + presentationOffset) * presentationScaler;
    248                     presentationScaler = presentation.ActualWidth / (presentation.chart.ActualWidth);
    249                     presentation.SetScaler(presentationScaler);
    250                     settings.Scale = (int)(presentationScaler * 1000.0);
    251                 }
    252 
    253                 // calculate presentation bars height
     271
     272                // calculate presentation bars height and add the to our local DataSource
    254273                foreach (KeyValuePair<string, double[]> item in grams)
    255274                {
    256                     int height = (int)(item.Value[PERCENTAGED] * (chartheight / (max * presentationScaler)));
    257                     //int height = (int)(item.Value[PERCENTAGED] * ((presentation.ActualHeight - presentation.sli.ActualHeight - (presentationOffset * presentationScaler)) / (max * presentationScaler)));
    258 
     275                    double height = item.Value[PERCENTAGED] * (maxBarHeight / max);
    259276                    CollectionElement row = new CollectionElement(height, Math.Round(item.Value[PERCENTAGED] * 100, 2), item.Key);
    260277                    data.ValueCollection.Add(row);
     
    284301        private void presentation_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
    285302        {
    286             // Just for debugging - maybe still need to hunt the width-bug (SizeChanged is not fired when presentation becomes wider)
     303            // Just for debugging
    287304            //if (e.HeightChanged)
    288305            //{
     
    294311            //    GuiLogMessage("Width changed from " + e.PreviousSize.Width + " to " + e.NewSize.Width, NotificationLevel.Info);
    295312            //}
    296             //GuiLogMessage("Chart size: AH=" + presentation.chart.ActualHeight + ", AW=" + presentation.chart.ActualWidth + "; H-slider=" + (presentation.ActualHeight - presentation.sli.ActualHeight), NotificationLevel.Info);
    297313
    298314            updatePresentation();
     
    309325
    310326                case "Scale":
    311                     presentation.SetScaler( (double)settings.Scale / 1000.0);
     327                    presentation.SetScaler( (double)settings.Scale / 10000.0);
    312328                    break;
    313329            }
     
    333349        public void Stop()
    334350        {
    335             //throw new NotImplementedException();
     351            presentation.SetBackground(Brushes.LightGray);
    336352        }
    337353
  • trunk/CrypPlugins/FrequencyTest/FrequencyTestPresentation.xaml

    r706 r738  
    55    Background="Transparent"
    66    SnapsToDevicePixels="True"
    7     HorizontalAlignment="Center"
    8              Height="Auto"
    9              Width="Auto"
    10             x:Name="usercontrol" >
     7    HorizontalAlignment="Stretch"
     8    VerticalAlignment="Stretch"
     9    Height="Auto"
     10    Width="Auto"
     11    x:Name="ChartControl" >
    1112   
    1213        <UserControl.Resources>
     
    5859   
    5960   
    60    
    61    
    62    
    63     <Grid VerticalAlignment="Stretch">
    64         <Grid.RowDefinitions>
    65             <RowDefinition />
    66             <RowDefinition Height="Auto" />
    67         </Grid.RowDefinitions>
     61         
     62    <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto"  ScrollViewer.HorizontalScrollBarVisibility="Auto"
     63                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
     64        <Grid x:Name="chart" Background="LightYellow" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
     65            <Grid.ColumnDefinitions>
     66                <ColumnDefinition Width="Auto" />
     67            </Grid.ColumnDefinitions>
     68            <Grid.RowDefinitions>
     69                <RowDefinition Height="Auto" />
     70                <RowDefinition Height="1*" />
     71            </Grid.RowDefinitions>
     72           
     73            <Grid.LayoutTransform>
     74                <ScaleTransform ScaleX="1" ScaleY="1"/>
     75            </Grid.LayoutTransform>
     76         
     77           <TextBlock x:Name="chartHeadline" TextAlignment="Center" Grid.Row="0" Grid.Column="0" FontSize="20" Foreground="DarkBlue"  FontFamily="Academy" OpacityMask="Turquoise" Text="No data available yet!" ></TextBlock>
     78
     79           <ItemsControl x:Name="chartBars" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"           
     80             ItemsSource="{Binding Source={StaticResource source},Path=ValueCollection}"
     81             ItemTemplate="{StaticResource template}" ItemsPanel="{StaticResource panelTemplate}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
     82           </ItemsControl>
     83
     84        </Grid>
     85    </ScrollViewer>
    6886       
    69         <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto"  ScrollViewer.HorizontalScrollBarVisibility="Auto">
    70             <Grid x:Name="chart" Grid.Row="0" VerticalAlignment="Stretch" >
    71                 <Grid.RowDefinitions>
    72                     <RowDefinition Height="Auto" />
    73                     <RowDefinition Height="1*" />
    74                 </Grid.RowDefinitions>
    75                
    76                 <Grid.LayoutTransform>
    77                     <ScaleTransform   ScaleX="{Binding ElementName=sli,Path=Value}" ScaleY="{Binding ElementName=sli, Path=Value}"/>
    78                 </Grid.LayoutTransform>
    79              
    80                <TextBlock x:Name="chartHeadline" TextAlignment="Center" Grid.Row="0" FontSize="20" Foreground="DarkBlue"  FontFamily="Academy" OpacityMask="Turquoise" Text="No data available yet!" ></TextBlock>
    81 
    82                <ItemsControl Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"           
    83                  ItemsSource="{Binding Source={StaticResource source},Path=ValueCollection}"
    84                  ItemTemplate="{StaticResource template}" ItemsPanel="{StaticResource panelTemplate}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
    85                </ItemsControl>
    86 
    87             </Grid>
    88         </ScrollViewer>
    89        
    90         <Slider x:Name="sli" Grid.Row="1" Width="100" HorizontalAlignment="Center" Minimum="0.05" VerticalAlignment="Bottom" Maximum="2" Value="1"/>
    91        
    92     </Grid>
    93    
    94    
    9587</UserControl>
    9688   
  • trunk/CrypPlugins/FrequencyTest/FrequencyTestPresentation.xaml.cs

    r706 r738  
    5757            Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    5858            {
    59                 sli.Value = value;
     59                chart.LayoutTransform = new ScaleTransform(value, value);
     60            }, null);
     61        }
     62
     63        public void SetBackground(Brush brush)
     64        {
     65            Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     66            {
     67                chart.Background = brush;
    6068            }, null);
    6169        }
  • trunk/CrypPlugins/FrequencyTest/FrequencyTestSettings.cs

    r737 r738  
    4747        private bool autozoom = true;
    4848        private int chartHeight = 160;
    49         private int scale = 1000; // = 1 , factor of 1000
     49        private int scale = 10000; // = 1 , factor of 10000
    5050
    5151        #endregion
     
    210210
    211211        [PropertySaveOrder(7)]
    212         [TaskPane("Zoom", "Zoom the chart", "Presentation", 22, true, DisplayLevel.Beginner, ControlType.Slider, 5, 2000)]
     212        [TaskPane("Zoom", "Zoom the chart", "Presentation", 22, true, DisplayLevel.Beginner, ControlType.Slider, 5, 20000)]
    213213        public int Scale
    214214        {
Note: See TracChangeset for help on using the changeset viewer.