Пример #1
0
        /// <summary>
        /// Draws the view
        /// </summary>
        /// <param name="drawing">drawing wrapper</param>
        /// <param name="options">drawing options</param>
        /// <param name="margin">drawing margin</param>
        public virtual void Draw(IDrawing drawing, IDrawOptions options, IMargin margin)
        {
            if (drawing == null || margin == null)
            {
                throw new InvalidArgumentException("parameter is null");
            }

            if (!(options is ScalingDrawOptions))
            {
                throw new InvalidArgumentException("options is not compatible");
            }
            var state = ((ScalingDrawOptions)options).State;

            var canvasSize = options.CanvasSize;
            var clip       = new RectangleF((float)margin.Left, (float)margin.Top, (float)(canvasSize.Width - margin.LeftAndRight), (float)(canvasSize.Height - margin.TopAndBottom));

            if (state.MovingStart != null && state.MovingPosition != null)
            {
                drawing.Line(state.MovingPenColor, state.MovingStart.Value.X, state.MovingStart.Value.Y, state.MovingPosition.Value.X, state.MovingPosition.Value.Y, clip);
            }

            if (state.ScalingStart != null && state.ScalingPosition != null)
            {
                Rectangle rectangle = SortCoordinates(state.ScalingStart.Value, state.ScalingPosition.Value);
                var       color     = state.ZoomIncrease ? state.ZoomInPenColor : state.ZoomOutPenColor;
                drawing.Rectangle(color, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, clip);
            }
        }
Пример #2
0
        private void DrawHorizontalLine(IGridState state, IDrawing drawing, Structs.Size canvasSize, IMargin margin, ref SizeF strY, double valueData, double stepData, bool calcWidth, ref double maxTextSize, StringAlignment align, ref int lastTextPos)
        {
            double y = this.scaleService.ToScreenY(valueData);

            if (y >= 0 && y <= canvasSize.Height - margin.Bottom - margin.Top)
            {
                if (calcWidth)
                {
                    var strValue = state.ItemFormatter.ToString(Axis.Y, new DataItem(0, valueData), stepData);
                    var strSize  = drawing.MeasureText(strValue);
                    maxTextSize = maxTextSize < strSize.Width ? strSize.Width : maxTextSize;
                    strY.Height = strSize.Height;
                }
                else
                {
                    double lineYPos = canvasSize.Height - margin.Bottom - y; // Invert graphic
                    var    color    = valueData != 0 ? state.GridColor : state.AxeColor;
                    drawing.Line(color, margin.Left, lineYPos, canvasSize.Width - margin.Right, lineYPos);

                    if (CalcAndCheckLabelRectY(state, canvasSize, margin, ref strY, valueData, align, lineYPos, out Rectangle rect, out bool borderValue))
                    {
                        var strValue = state.ItemFormatter.ToString(Axis.Y, new DataItem(0, valueData), stepData);
                        drawing.Text(state.TextYColor, rect, strValue, StringAlignment.Far, align);

                        lastTextPos = rect.Top;
                    }
                }
            }
        }
Пример #3
0
        private static void DrawVerticalLine(IGridState state, IDrawing drawing, Structs.Size canvasSize, IMargin margin, SizeF strX, double screenPos, double valueData, double maxData, double stepData, StringAlignment align, ref int lastTextPos)
        {
            if (screenPos >= 0 &&
                (align == StringAlignment.Center && (screenPos <= canvasSize.Width - margin.Left - margin.Right - strX.Width / 2) ||
                 (align == StringAlignment.Far && (screenPos - strX.Width <= canvasSize.Width - margin.Left - margin.Right))))
            {
                double lineXPos = screenPos + margin.Left;
                var    color    = valueData != 0 ? state.GridColor : state.AxeColor;
                drawing.Line(color, lineXPos, margin.Top, lineXPos, canvasSize.Height - margin.Bottom);

                if (CalcAndCheckLabelRectX(state, ref canvasSize, margin, ref strX, valueData, maxData, align, lineXPos, ref lastTextPos, out Rectangle rect))
                {
                    double linePos2 = canvasSize.Height - margin.Bottom;
                    drawing.Line(color, lineXPos, linePos2, lineXPos, linePos2 + state.LabelPadding.Top + 1);

                    var strValue = state.ItemFormatter.ToString(Axis.X, new DataItem(valueData, 0), stepData);
                    drawing.Text(state.TextXColor, rect, strValue, align, StringAlignment.Center);

                    lastTextPos = rect.Right;
                }
            }
        }
Пример #4
0
        private void DrawAllData(IDataDrawState state, IDrawing drawing, IMargin margin, Size canvasSize, System.Drawing.RectangleF clip)
        {
            var startX = this.scaleService.State.X1;
            var endX   = this.scaleService.State.X2;

            if (this.dataService.ItemCount == 1)
            {
                // Draw point for single data item
                foreach (var item in this.dataService.GetItems(startX, endX))
                {
                    if (item != null && this.scaleService.IsItemVisible(item))
                    {
                        var x = this.scaleService.ToScreen(Axis.X, item.X);
                        var y = this.scaleService.ToScreen(Axis.Y, item.Y);
                        drawing.Circle(state.LineColor, margin.Left + x, canvasSize.Height - margin.Bottom - y, 4, clip);
                    }
                }
            }
            else
            {
                IDataItem prevItem = null;
                // Draw lines
                foreach (var item in this.dataService.GetItems(startX, endX))
                {
                    if (item != null && prevItem != null &&
                        (this.scaleService.IsItemVisible(prevItem) ||
                         this.scaleService.IsItemVisible(item)))
                    {
                        var x1 = this.scaleService.ToScreen(Axis.X, prevItem.X);
                        var y1 = this.scaleService.ToScreen(Axis.Y, prevItem.Y);

                        var x2 = this.scaleService.ToScreen(Axis.X, item.X);
                        var y2 = this.scaleService.ToScreen(Axis.Y, item.Y);

                        drawing.Line(state.LineColor, margin.Left + x1, canvasSize.Height - margin.Bottom - y1, margin.Left + x2, canvasSize.Height - margin.Bottom - y2, clip);
                    }

                    prevItem = item;
                }
            }
        }