Ejemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="ChartElement.Updated"/> event.
        /// </summary>
        /// <remarks>
        /// <strong>Notes to Inheritors:</strong> When overriding <see cref="OnUpdate"/> in a
        /// derived class, be sure to call the base class's <see cref="OnUpdate"/> method so that
        /// registered delegates receive the event.
        /// </remarks>
        protected override void OnUpdate()
        {
            _verticalMajorLinesRenderer.Clear();
            _horizontalMajorLinesRenderer.Clear();
            _verticalMinorLinesRenderer.Clear();
            _horizontalMinorLinesRenderer.Clear();

#if SILVERLIGHT
            UpdateMajorGridLines();
            UpdateMinorGridLines();
#else
            switch (RenderMode)
            {
            case ChartRenderMode.Quality:
                // Update grid lines immediately.
                UpdateMajorGridLines();
                UpdateMinorGridLines();
                break;

            case ChartRenderMode.Performance:
                // Update major grid lines immediately.
                UpdateMajorGridLines();

                // Temporarily disable bitmap cache and anti-aliasing.
                // Update minor grid lines when application is idle.
                if (!_updatePending)
                {
                    _updatePending = true;
                    ClearCacheMode();
                    ClearEdgeMode();
                    ChartHelper.Defer(Dispatcher, () =>
                    {
                        if (_updatePending)
                        {
                            _updatePending = false;
                            UpdateMinorGridLines();
                            RestoreCacheMode();
                            RestoreEdgeMode();
                        }
                    });
                }
                break;

            case ChartRenderMode.DoNotRender:
                // Do nothing.
                break;
            }
#endif

            base.OnUpdate();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Raises the <see cref="ChartElement.Updated"/> event.
        /// </summary>
        /// <remarks>
        /// <strong>Notes to Inheritors:</strong> When overriding <see cref="OnUpdate"/> in a
        /// derived class, be sure to call the base class's <see cref="OnUpdate"/> method so that
        /// the base class <see cref="Chart"/> can update the data source if required.
        /// </remarks>
        protected override void OnUpdate()
        {
            base.OnUpdate();  // Updates the data source, if required.

            // Cleanup
            _lineRenderer.Clear();
            _areaRenderer.Clear();

            Debug.Assert(Canvas.Children.Count == 0, "Canvas should be cleared in base class.");
            Canvas.Children.Add(_areaPath);
            Canvas.Children.Add(_linePath);

            if (Data != null && Data.Count != 0)
            {
                // Clip filled area and lines to the chart area.
                Rect chartArea = ChartPanel.GetChartAreaBounds(XAxis, YAxis);

                // Allow line to draw on chart axes.
                Rect lineClipRect = new Rect(chartArea.Left - 2, chartArea.Top - 2, chartArea.Width + 4, chartArea.Height + 4);
                LineClipGeometry = new RectangleGeometry {
                    Rect = lineClipRect
                };

                // Keep area inside the chart area.
                Rect areaClipRect = chartArea;
                AreaClipGeometry = new RectangleGeometry {
                    Rect = areaClipRect
                };

                FindVisibleDataPoints();
                CachePositions();

#if SILVERLIGHT
                OnUpdateLines(_startIndex, _endIndexExclusive, _xPositions, _basePositions, _yPositions);
                UpdateMarkers();
#else
                switch (RenderMode)
                {
                case ChartRenderMode.Quality:
                    // Update lines and markers immediately.
                    OnUpdateLines(_startIndex, _endIndexExclusive, _xPositions, _basePositions, _yPositions);
                    UpdateMarkers();
                    break;

                case ChartRenderMode.Performance:
                    // Immediately update lines.
                    OnUpdateLines(_startIndex, _endIndexExclusive, _xPositions, _basePositions, _yPositions);

                    // Temporarily disable bitmap cache and anti-aliasing.
                    // Update markers when application is idle.
                    if (!_updatePending)
                    {
                        _updatePending = true;
                        ClearCacheMode();
                        ClearEdgeMode();
                        ChartHelper.Defer(Dispatcher, () =>
                        {
                            if (_updatePending)
                            {
                                _updatePending = false;
                                UpdateMarkers();
                                RestoreCacheMode();
                                RestoreEdgeMode();
                            }
                        });
                    }
                    break;

                case ChartRenderMode.DoNotRender:
                    // Do nothing.
                    break;
                }
#endif
            }
        }