示例#1
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal
        /// processes call <see cref="FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            _horizontalMajorLinesRenderer = null;
            _horizontalMinorLinesRenderer = null;
            _verticalMajorLinesRenderer   = null;
            _verticalMinorLinesRenderer   = null;

            base.OnApplyTemplate();
            var horizontalMajorLinesPath = GetTemplateChild("PART_HorizontalMajorLines") as Path;
            var horizontalMinorLinesPath = GetTemplateChild("PART_HorizontalMinorLines") as Path;
            var verticalMajorLinesPath   = GetTemplateChild("PART_VerticalMajorLines") as Path;
            var verticalMinorLinesPath   = GetTemplateChild("PART_VerticalMinorLines") as Path;

            if (horizontalMajorLinesPath != null)
            {
                _horizontalMajorLinesRenderer = new PathRenderer(horizontalMajorLinesPath);
            }

            if (horizontalMinorLinesPath != null)
            {
                _horizontalMinorLinesRenderer = new PathRenderer(horizontalMinorLinesPath);
            }

            if (verticalMajorLinesPath != null)
            {
                _verticalMajorLinesRenderer = new PathRenderer(verticalMajorLinesPath);
            }

            if (verticalMinorLinesPath != null)
            {
                _verticalMinorLinesRenderer = new PathRenderer(verticalMinorLinesPath);
            }

            Invalidate();
        }
示例#2
0
        /// <inheritdoc/>
        public override void OnApplyTemplate()
        {
            _lineRenderer = null;
            _areaRenderer = null;

            base.OnApplyTemplate();

            _linePath = GetTemplateChild("PART_Line") as Path ?? new Path {
                Style = LineStyle
            };
            _areaPath = GetTemplateChild("PART_Area") as Path ?? new Path {
                Style = AreaStyle
            };

            _lineRenderer = new PathRenderer(_linePath);
            _areaRenderer = new PathRenderer(_areaPath);

            Invalidate();
        }
示例#3
0
        /// <inheritdoc/>
        public override void OnApplyTemplate()
        {
            _lineRenderer = null;
            _areaRenderer = null;

            base.OnApplyTemplate();

            _linePath = GetTemplateChild("PART_Line") as Path ?? new Path { Style = LineStyle };
            _areaPath = GetTemplateChild("PART_Area") as Path ?? new Path { Style = AreaStyle };

            _lineRenderer = new PathRenderer(_linePath);
            _areaRenderer = new PathRenderer(_areaPath);

            Invalidate();
        }
示例#4
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal
        /// processes call <see cref="FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (_canvas != null)
            {
                // Clean up previous canvas
                foreach (TextBlock tickTextBlock in _tickLabels)
                {
                    _canvas.Children.Remove(tickTextBlock);
                    _tickLabels.Clear();
                }

                _canvas.Children.Remove(_hitRectangle);
                _hitRectangle = null;
                _canvas = null;
            }

            _axisLine = null;
            _majorTickRenderer = null;
            _minorTickRenderer = null;

            if (_titleContentControl != null)
            {
                _titleContentControl.SizeChanged -= OnTitleSizeChanged;
                _titleContentControl = null;
            }

            base.OnApplyTemplate();

            _canvas = GetTemplateChild("PART_Canvas") as Canvas;
            _axisLine = GetTemplateChild("PART_AxisLine") as Line;
            var majorTicksPath = GetTemplateChild("PART_MajorTicks") as Path;
            var minorTicksPath = GetTemplateChild("PART_MinorTicks") as Path;
            _titleContentControl = GetTemplateChild("PART_Title") as ContentControl;

            if (_canvas != null)
            {
                // Create an invisible rectangle that is used only for hit-testing.
                _hitRectangle = new Rectangle { Fill = new SolidColorBrush(Colors.Transparent) };
#if SILVERLIGHT
                Canvas.SetZIndex(_hitRectangle, -1);
#else
                Panel.SetZIndex(_hitRectangle, -1);
#endif
                _canvas.Children.Add(_hitRectangle);
            }

            if (majorTicksPath != null)
                _majorTickRenderer = new PathRenderer(majorTicksPath);

            if (minorTicksPath != null)
                _minorTickRenderer = new PathRenderer(minorTicksPath);

            if (_titleContentControl != null)
                _titleContentControl.SizeChanged += OnTitleSizeChanged;

            Invalidate();
        }
示例#5
0
        /// <summary>
        /// Creates a tick on the axis.
        /// </summary>
        /// <param name="value">The value at which the ticks should be drawn.</param>
        /// <param name="tickLength">Length of the tick.</param>
        /// <param name="renderContext">The render context.</param>
        /// <returns>The bounding rectangle of the tick.</returns>
        private Rect AddTick(double value, double tickLength, PathRenderer.Context renderContext)
        {
            // Determine start and end point of the tick.
            double position = GetPosition(value);
            Point start;
            Point end;

            bool oneSidedTicks = OneSidedTicks;

            if (_isXAxis)
            {
                if (LabelsAboveAxis)
                {
                    start = oneSidedTicks ? new Point(position, _originY) : new Point(position, _originY + 0.5 * tickLength);
                    end = new Point(start.X, start.Y - tickLength);
                }
                else
                {
                    start = oneSidedTicks ? new Point(position, _originY) : new Point(position, _originY - 0.5 * tickLength);
                    end = new Point(start.X, start.Y + tickLength);
                }
            }
            else
            {
                if (LabelsAboveAxis)
                {
                    start = oneSidedTicks ? new Point(_originX, position) : new Point(_originX + 0.5 * tickLength, position);
                    end = new Point(start.X - tickLength, start.Y);
                }
                else
                {
                    start = oneSidedTicks ? new Point(_originX, position) : new Point(_originX - 0.5 * tickLength, position);
                    end = new Point(start.X + tickLength, start.Y);
                }
            }

            renderContext.DrawLine(start, end);

            _internalTitleOffset = Math.Max(_internalTitleOffset, tickLength);

            // Estimate bounds
            Rect bounds;
            if (IsXAxis)
            {
                if (LabelsAboveAxis)
                    bounds = new Rect(end.X - 0.5, end.Y, 1, tickLength);
                else
                    bounds = new Rect(start.X - 0.5, start.Y, 1, tickLength);
            }
            else
            {
                if (LabelsAboveAxis)
                    bounds = new Rect(end.X, end.Y - 0.5, tickLength, 1);
                else
                    bounds = new Rect(start.X, start.Y - 0.5, tickLength, 1);
            }

            return bounds;
        }
示例#6
0
        /// <inheritdoc/>
        protected override UIElement OnGetLegendSymbol()
        {
            var grid = new Grid
            {
                MinWidth  = 16,
                MinHeight = 16,
            };

            if (HorizontalMajorLineStyle != null)
            {
                var horizontalMajorLines = new Path {
                    Width = 16, Height = 16, Stretch = Stretch.Uniform
                };
                horizontalMajorLines.SetBinding(StyleProperty, new Binding("HorizontalMajorLineStyle")
                {
                    Source = this
                });
                using (var renderContext = new PathRenderer(horizontalMajorLines).Open())
                {
                    renderContext.DrawLine(new Point(0, 0), new Point(16, 0));
                    renderContext.DrawLine(new Point(0, 8), new Point(16, 8));
                    renderContext.DrawLine(new Point(0, 16), new Point(16, 16));
                }
                grid.Children.Add(horizontalMajorLines);
            }

            if (HorizontalMinorLineStyle != null)
            {
                var horizontalMinorLines = new Path {
                    Width = 16, Height = 16, Stretch = Stretch.Uniform
                };
                horizontalMinorLines.SetBinding(StyleProperty, new Binding("HorizontalMinorLineStyle")
                {
                    Source = this
                });
                using (var renderContext = new PathRenderer(horizontalMinorLines).Open())
                {
                    renderContext.DrawLine(new Point(0, 4), new Point(16, 4));
                    renderContext.DrawLine(new Point(0, 12), new Point(16, 12));
                }
                grid.Children.Add(horizontalMinorLines);
            }

            if (VerticalMajorLineStyle != null)
            {
                var verticalMajorLines = new Path {
                    Width = 16, Height = 16, Stretch = Stretch.Uniform
                };
                verticalMajorLines.SetBinding(StyleProperty, new Binding("VerticalMajorLineStyle")
                {
                    Source = this
                });
                using (var renderContext = new PathRenderer(verticalMajorLines).Open())
                {
                    renderContext.DrawLine(new Point(0, 0), new Point(0, 16));
                    renderContext.DrawLine(new Point(8, 0), new Point(8, 16));
                    renderContext.DrawLine(new Point(16, 0), new Point(16, 16));
                }
                grid.Children.Add(verticalMajorLines);
            }

            if (VerticalMinorLineStyle != null)
            {
                var verticalMinorLines = new Path {
                    Width = 16, Height = 16, Stretch = Stretch.Uniform
                };
                verticalMinorLines.SetBinding(StyleProperty, new Binding("VerticalMinorLineStyle")
                {
                    Source = this
                });
                using (var renderContext = new PathRenderer(verticalMinorLines).Open())
                {
                    renderContext.DrawLine(new Point(4, 0), new Point(4, 16));
                    renderContext.DrawLine(new Point(12, 0), new Point(12, 16));
                }
                grid.Children.Add(verticalMinorLines);
            }

            return(grid);
        }
示例#7
0
        /// <inheritdoc/>
        protected override UIElement OnGetLegendSymbol()
        {
            var grid = new Grid
            {
                MinWidth = 16,
                MinHeight = 16,
            };

            if (HorizontalMajorLineStyle != null)
            {
                var horizontalMajorLines = new Path { Width = 16, Height = 16, Stretch = Stretch.Uniform };
                horizontalMajorLines.SetBinding(StyleProperty, new Binding("HorizontalMajorLineStyle") { Source = this });
                using (var renderContext = new PathRenderer(horizontalMajorLines).Open())
                {
                    renderContext.DrawLine(new Point(0, 0), new Point(16, 0));
                    renderContext.DrawLine(new Point(0, 8), new Point(16, 8));
                    renderContext.DrawLine(new Point(0, 16), new Point(16, 16));
                }
                grid.Children.Add(horizontalMajorLines);
            }

            if (HorizontalMinorLineStyle != null)
            {
                var horizontalMinorLines = new Path { Width = 16, Height = 16, Stretch = Stretch.Uniform };
                horizontalMinorLines.SetBinding(StyleProperty, new Binding("HorizontalMinorLineStyle") { Source = this });
                using (var renderContext = new PathRenderer(horizontalMinorLines).Open())
                {
                    renderContext.DrawLine(new Point(0, 4), new Point(16, 4));
                    renderContext.DrawLine(new Point(0, 12), new Point(16, 12));
                }
                grid.Children.Add(horizontalMinorLines);
            }

            if (VerticalMajorLineStyle != null)
            {
                var verticalMajorLines = new Path { Width = 16, Height = 16, Stretch = Stretch.Uniform };
                verticalMajorLines.SetBinding(StyleProperty, new Binding("VerticalMajorLineStyle") { Source = this });
                using (var renderContext = new PathRenderer(verticalMajorLines).Open())
                {
                    renderContext.DrawLine(new Point(0, 0), new Point(0, 16));
                    renderContext.DrawLine(new Point(8, 0), new Point(8, 16));
                    renderContext.DrawLine(new Point(16, 0), new Point(16, 16));
                }
                grid.Children.Add(verticalMajorLines);
            }

            if (VerticalMinorLineStyle != null)
            {
                var verticalMinorLines = new Path { Width = 16, Height = 16, Stretch = Stretch.Uniform };
                verticalMinorLines.SetBinding(StyleProperty, new Binding("VerticalMinorLineStyle") { Source = this });
                using (var renderContext = new PathRenderer(verticalMinorLines).Open())
                {
                    renderContext.DrawLine(new Point(4, 0), new Point(4, 16));
                    renderContext.DrawLine(new Point(12, 0), new Point(12, 16));
                }
                grid.Children.Add(verticalMinorLines);
            }

            return grid;
        }
示例#8
0
        //--------------------------------------------------------------
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal
        /// processes call <see cref="FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            _horizontalMajorLinesRenderer = null;
            _horizontalMinorLinesRenderer = null;
            _verticalMajorLinesRenderer = null;
            _verticalMinorLinesRenderer = null;

            base.OnApplyTemplate();
            var horizontalMajorLinesPath = GetTemplateChild("PART_HorizontalMajorLines") as Path;
            var horizontalMinorLinesPath = GetTemplateChild("PART_HorizontalMinorLines") as Path;
            var verticalMajorLinesPath = GetTemplateChild("PART_VerticalMajorLines") as Path;
            var verticalMinorLinesPath = GetTemplateChild("PART_VerticalMinorLines") as Path;

            if (horizontalMajorLinesPath != null)
                _horizontalMajorLinesRenderer = new PathRenderer(horizontalMajorLinesPath);

            if (horizontalMinorLinesPath != null)
                _horizontalMinorLinesRenderer = new PathRenderer(horizontalMinorLinesPath);

            if (verticalMajorLinesPath != null)
                _verticalMajorLinesRenderer = new PathRenderer(verticalMajorLinesPath);

            if (verticalMinorLinesPath != null)
                _verticalMinorLinesRenderer = new PathRenderer(verticalMinorLinesPath);

            Invalidate();
        }