コード例 #1
0
ファイル: GridView.cs プロジェクト: serge4k/GraphControl
        /// <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 GridDrawOptions))
            {
                throw new InvalidArgumentException("options is not compatible");
            }
            var state = ((GridDrawOptions)options).State;

            var canvasSize = options.CanvasSize;

            // Step 1 - Measure all texts and calc offsets
            MeashureLabelSizes(drawing, margin, state, canvasSize, out SizeF strX, out SizeF strY, out double stepDataY);

            // Step 2 - Draw vertical lines
            DrawVerticalLines(drawing, margin, state, canvasSize, strX, out double stepDataX);

            // Step 3 - Draw horizontal lines
            DrawHorizontalLines(drawing, margin, state, canvasSize, ref strY, ref stepDataY);

            // Step 4 - Draw axis X and Y
            DrawAxis(drawing, margin, state, canvasSize, strX, strY, stepDataY, stepDataX);

            this.scaleService.SetStepX(stepDataX);
            this.scaleService.SetStepY(stepDataY);
        }
コード例 #2
0
ファイル: DataView.cs プロジェクト: serge4k/GraphControl
        /// <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 DataDrawOptions))
            {
                throw new InvalidArgumentException("options is not compatible");
            }
            var state = ((DataDrawOptions)options).State;

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

            if (options.DrawOnlyNewData)
            {
                DrawNewData(state, drawing, options, margin, canvasSize, clip);
            }
            else
            {
                DrawAllData(state, drawing, margin, canvasSize, clip);
            }
        }
コード例 #3
0
        protected virtual void DrawGraphInBuffer(IDrawOptions options)
        {
            if (options == null)
            {
                throw new InvalidArgumentException("parameter is null");
            }

            // Do not draw if canvas size is 0
            if (options.CanvasSize.Width == 0 || options.CanvasSize.Height == 0)
            {
                return;
            }

            // Check that buffer was not created or recreate when size was changed
            if (this.drawingBuffer == null ||
                this.drawingBuffer.CanvasSize.Width != options.CanvasSize.Width ||
                this.drawingBuffer.CanvasSize.Height != options.CanvasSize.Height)
            {
                this.drawingBuffer = new DrawingBuffer(options.CanvasSize);
            }

            this.UpdateScale?.Invoke(this, new UpdateScaleEventArgs(options));

            // Draw in buffer
            using (var drawing = new Drawing2DWrapper(this.drawingBuffer.Graphics))
            {
                this.DrawGraph?.Invoke(this, new DrawGraphEventArgs(drawing, options));
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: DrawOptions.cs プロジェクト: serge4k/GraphControl
 public DrawOptions(IDrawOptions options)
 {
     if (options == null)
     {
         throw new InvalidArgumentException("parameter is null");
     }
     this.CanvasSize = options.CanvasSize;
     this.FitToX     = options.FitToX;
     this.FitToY     = options.FitToY;
     this.NewItems   = options.NewItems;
 }
コード例 #6
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 void Draw(IDrawing drawing, IDrawOptions options, IMargin margin)
        {
            if (options == null)
            {
                throw new InvalidArgumentException("parameter is null");
            }

            // Fix 1 - User can not move/zoom after pressing Fit by Y button
            // Update Fit By states from curent drawing operation
            this.state.FitByX = options.FitToX;
            this.state.FitByY = options.FitToY;

            this.view.Draw(drawing, new ScalingDrawOptions(options, this.state), margin);
        }
コード例 #7
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 BackgroundDrawOptions))
            {
                throw new InvalidArgumentException("options is not compatible");
            }
            var state = ((BackgroundDrawOptions)options).State;

            drawing.FillRectangle(state.PenColor, state.BackgroundColor, 0, 0, options.CanvasSize.Width - 1, options.CanvasSize.Height - 1);
        }
コード例 #8
0
        /// <summary>
        /// Posts event to draw in buffer async
        /// </summary>
        /// <param name="options">draw options</param>
        public void DrawGraphInBufferAsync(IDrawOptions options)
        {
            lock (this.drawingTaskSink)
            {
                if (this.drawingTaskCanvasOptions.Count > 2)
                {
                    this.LastQueueOverflow = DateTime.UtcNow;
                    this.drawingTaskCanvasOptions.Dequeue();
                }

                this.drawingTaskCanvasOptions.Enqueue(options);

                this.drawingRequestEvent.Set();

                if (this.drawingTask == null)
                {
                    this.drawingTask = Task.Factory.StartNew(new Action(DrawGraphInBufferAction));
                }
            }
        }
コード例 #9
0
ファイル: DataView.cs プロジェクト: serge4k/GraphControl
        private void DrawNewData(IDataDrawState state, IDrawing drawing, IDrawOptions options, IMargin margin, Size canvasSize, System.Drawing.RectangleF clip)
        {
            if (options.NewItems.Count == 1)
            {
                // Draw point for single data item
                foreach (var item in options.NewItems)
                {
                    if (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 options.NewItems)
                {
                    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;
                }
            }
        }
コード例 #10
0
 public DataDrawOptions(IDrawOptions options, IDataDrawState state) : base(options, state)
 {
 }
コード例 #11
0
 public GridDrawOptions(IDrawOptions options, IGridState state) : base(options, state)
 {
 }
コード例 #12
0
 public BackgroundDrawOptions(IDrawOptions options, IBackgroundState state)
     : base(options, state)
 {
 }
コード例 #13
0
 public ScalingDrawOptions(IDrawOptions options, IScalingState state) : base(options, state)
 {
 }
コード例 #14
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 void Draw(IDrawing drawing, IDrawOptions options, IMargin margin)
 {
     this.View.Draw(drawing, new BackgroundDrawOptions(options, state), margin);
 }
コード例 #15
0
 /// <summary>
 /// Refresh view / control with options (IRefreshControlView implementation)
 /// </summary>
 public void RefreshView(IDrawOptions options)
 {
     this.DrawGraph?.Invoke(this, new DrawGraphEventArgs(null, options));
 }
コード例 #16
0
        /// <summary>
        /// Update scale interface (IScaleUpdate)
        /// </summary>
        /// <param name="options">drawing options</param>
        public void UpdateScale(IDrawOptions options)
        {
            if (options == null)
            {
                throw new InvalidArgumentException("parameter is null");
            }

            var canvasSize = options.CanvasSize;
            var margin     = this.scaleState.Margin;

            if (options.FitToX)
            {
                this.scaleState.X1 = this.dataService.GetMin(Axis.X);
                this.scaleState.X2 = this.dataService.GetMax(Axis.X);
            }

            var x1 = this.scaleState.X1;
            var x2 = this.scaleState.X2;

            if (x1 == 0 && x2 == 0)
            {
                this.scaleState.ScaleX = 1;
            }
            else if (x1 == x2)
            {
                this.scaleState.ScaleX = 1;
            }
            else
            {
                if (canvasSize.Height < margin.Top - margin.Bottom)
                {
                    throw new GraphControlException($"Control size is too small (Width: {canvasSize.Width} less than margin: {margin.Left - margin.Right} ");
                }
                this.scaleState.ScaleX = (canvasSize.Width - margin.Left - margin.Right) / (x2 - x1);
            }

            if (options.FitToY)
            {
                this.scaleState.Y1 = this.dataService.GetMin(Axis.Y);
                this.scaleState.Y2 = this.dataService.GetMax(Axis.Y);
            }

            var y1 = this.scaleState.Y1;
            var y2 = this.scaleState.Y2;

            if (y1 == 0 && y2 == 0)
            {
                this.scaleState.ScaleY = 1;
            }
            else if (y1 == y2)
            {
                this.scaleState.ScaleY = 1;
            }
            else
            {
                if (canvasSize.Height < margin.Top - margin.Bottom)
                {
                    throw new GraphControlException($"Control size is too small (Height: {canvasSize.Height} less than margin: {margin.Top - margin.Bottom} ");
                }
                this.scaleState.ScaleY = (canvasSize.Height - margin.Top - margin.Bottom) / (y2 - y1);
            }
        }
コード例 #17
0
 public UpdateScaleEventArgs(IDrawOptions drawOptions)
 {
     this.DrawOptions = drawOptions;
 }
コード例 #18
0
ファイル: DataPresenter.cs プロジェクト: serge4k/GraphControl
 /// <summary>
 /// Draws the view
 /// </summary>
 /// <param name="drawing">drawing wrapper</param>
 /// <param name="options">drawing options</param>
 /// <param name="margin">drawing margin</param>
 public void Draw(IDrawing drawing, IDrawOptions options, IMargin margin)
 {
     this.view.Draw(drawing, new DataDrawOptions(options, this.state), margin);
 }
コード例 #19
0
 public DrawGraphEventArgs(IDrawing drawing, IDrawOptions drawOptions)
 {
     this.Drawing     = drawing;
     this.DrawOptions = drawOptions;
 }