コード例 #1
0
        /// <summary>
        /// Indicate window/chart size.
        /// </summary>
        private void IndicateWindowChartSize()
        {
            var rct = WindowSupplement.GetWindowRect(this);
            var innerPlotAreaSize = ChartInnerPlotAreaSize();

            ShowStatus(String.Format("Window {0}-{1} Chart {2}-{3}",
                                     rct.Width,
                                     rct.Height,
                                     innerPlotAreaSize.Width,
                                     innerPlotAreaSize.Height));
        }
コード例 #2
0
        private void OnSizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (_diskChart != null)
            {
                AdjustChartAppearance();
            }

            // Binding in XAML will not work when window is maximized.
            this.MenuTop.Width = WindowSupplement.GetClientAreaSize(this).Width;

            if (IndicatesSize)
            {
                IndicateWindowChartSize();
            }
        }
コード例 #3
0
        /// <summary>
        /// Open Monitor window.
        /// </summary>
        private void OpenExecuted(object target, ExecutedRoutedEventArgs e)
        {
            try
            {
                var monitorWindow = this.OwnedWindows.OfType <MonitorWindow>().FirstOrDefault();
                if (monitorWindow != null)
                {
                    // Activate Monitor window.
                    WindowSupplement.ActivateWindow(monitorWindow);
                    return;
                }

                // Open Monitor Window.
                monitorWindow = new MonitorWindow {
                    Owner = this
                };
                monitorWindow.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                ProductInfo.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #4
0
        private void AdjustChartAppearance()
        {
            if (_diskChart == null)
            {
                return;
            }

            // ------------------
            // Set size of Chart.
            // ------------------
            // Width will be automatically resized except initial adjustment where it is required to set ChartArea.InnerPlotPosition.X.
            _diskChart.Width  = (int)WindowSupplement.GetClientAreaSize(this).Width;
            _diskChart.Height = (int)(WindowSupplement.GetClientAreaSize(this).Height - this.GridDashboard.ActualHeight * WindowDpiFactorY);

            var chartAreaOne = _diskChart.ChartAreas[0];

            // -----------------------------------------------------
            // Adjust maximum and minimum values in scales of Chart.
            // -----------------------------------------------------
            // X axis
            chartAreaOne.AxisX.Maximum = Settings.Current.AreaLocation + Settings.Current.AreaSize;
            chartAreaOne.AxisX.Minimum = Settings.Current.AreaLocation;

            // Y axis
            double chartMax;
            double chartMin;

            if (IsChartMaxFixed)
            {
                chartMax = ChartMax;
            }
            else
            {
                chartMax = (DiskScores[0].Data != null)
                                        ? Math.Ceiling(DiskScores[0].Data.Values.Max() / _chartUnit) * _chartUnit
                                        : _chartMaxDefault;
            }

            if (IsChartMinFixed)
            {
                chartMin = ChartMin;
            }
            else
            {
                chartMin = (DiskScores[0].Data != null)
                                        ? Math.Floor(DiskScores[0].Data.Values.Min() / _chartUnit) * _chartUnit
                                        : _chartMinDefault;
            }

            if (chartMin + _chartUnit > chartMax)      // If relationship between maximum and minimum values is screwed.
            {
                if ((chartMin == 0D) |                 // Case where minimum value is already 0.
                    (!IsChartMaxFixed &&
                     IsChartMinFixed))                 // Case where maximum value is not fixed and minimum value is fixed.
                {
                    chartMax = chartMin + _chartUnit;
                }
                else                 // Any other case.
                {
                    chartMin = chartMax - _chartUnit;
                }
            }

            chartAreaOne.AxisY.Maximum = chartMax;
            chartAreaOne.AxisY.Minimum = chartMin;

            // -----------------------------------------------------
            // Adjust size and position of inner plot area of Chart.
            // -----------------------------------------------------
            int digitX = 4;             // Digit number of maximum scale in X axis
            int digitY = 3;             // Digit number of maximum scale in Y axis

            if (DiskScores[0].Data != null)
            {
                digitX = Math.Max(digitX, chartAreaOne.AxisX.Maximum.ToString(CultureInfo.InvariantCulture).Length);
                digitY = Math.Max(digitY, chartAreaOne.AxisY.Maximum.ToString(CultureInfo.InvariantCulture).Length);
            }

            var labelX = TextSize(digitX, chartAreaOne.AxisX.LabelStyle.Font);
            var labelY = TextSize(digitY, chartAreaOne.AxisY.LabelStyle.Font);

            // Note that all properties are percentage.
            chartAreaOne.InnerPlotPosition.Auto = false;

            chartAreaOne.InnerPlotPosition.X = GetPerc(labelY.Width + 2, _diskChart.Width);
            chartAreaOne.InnerPlotPosition.Y = GetPerc(labelY.Height / 2, _diskChart.Height);

            chartAreaOne.InnerPlotPosition.Width  = 100f - GetPerc((labelY.Width + 2) + (labelX.Width / 2), _diskChart.Width);
            chartAreaOne.InnerPlotPosition.Height = 100f - GetPerc((labelY.Height / 2) + (labelX.Height * 2), _diskChart.Height);

            // --------------------------------
            // Adjust scale intervals of Chart.
            // --------------------------------
            var shortest = 40D * WindowDpiFactorY;

            // X axis
            double innerX    = _diskChart.Width * (chartAreaOne.InnerPlotPosition.Width / 100D);
            double intervalX = 256D;             // This is fallback number in case appropriate number can not be found.

            for (int i = 2; i <= 10; i++)        // 10 means very large number.
            {
                var interval = innerX / Math.Pow(2, i);

                if (interval < shortest)
                {
                    intervalX = Settings.Current.AreaSize / Math.Pow(2, i - 1);
                    break;
                }
            }

            chartAreaOne.AxisX.Interval            = intervalX;
            chartAreaOne.AxisX.MinorGrid.Interval  = intervalX / 2;
            chartAreaOne.AxisX.LabelStyle.Interval = intervalX * 2;             // 1 label per 2 major grids

            // Y axis
            double innerY    = _diskChart.Height * (chartAreaOne.InnerPlotPosition.Height / 100D);
            double intervalY = 100D;                                                    // This is fallback number in case appropriate number can not be found.
            var    intervals = new double[] { 5, 10, 20, 25, 50, 100, 200, 500, 1000 }; // Numbers to be used as interval

            for (int i = 0; i < intervals.Length; i++)
            {
                if ((chartMax - chartMin) % intervals[i] > 0D)
                {
                    continue;
                }

                var interval = innerY * intervals[i] / (chartMax - chartMin);

                if (interval > shortest)
                {
                    intervalY = intervals[i];
                    break;
                }
            }

            chartAreaOne.AxisY.Interval           = intervalY;
            chartAreaOne.AxisY.MinorGrid.Interval = intervalY / 2;
        }