Esempio n. 1
0
        /// <summary>
        /// Draw a row of data.
        /// </summary>
        private void DrawRowSmooth(Graphics graphics, SmoothInfo si)
        {
            double valueA, valueB;

            if (!this.TryGetValue(si.A.ColumnIndex, si.A.RowIndex, out valueA))
            {
                return;
            }

            if (!this.TryGetValue(si.B.ColumnIndex, si.B.RowIndex, out valueB))
            {
                return;
            }

            float x1 = this.GetRowX(si.A.ColumnIndex);
            float y1 = this.GetRowY(si.MinValue, si.MaxValue, valueA);
            float x2 = this.GetRowX(si.B.ColumnIndex);
            float y2 = this.GetRowY(si.MinValue, si.MaxValue, valueB);

            using (Pen pen = new Pen(Color.Blue, 3))
            {
                graphics.DrawLine(
                    pen,
                    x1,
                    y1,
                    x2,
                    y2);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculate the 'SmoothInfo' for a selected set of cells.
        /// </summary>
        private SmoothInfo GetSmoothInfo(double min, double max)
        {
            DataGridViewSelectedCellCollection selected = this.dataGrid.SelectedCells;

            if (this.SelectedColumn(selected))
            {
                SmoothInfo result = new SmoothInfo();
                result.MinValue = min;
                result.MaxValue = max;
                IEnumerable <DataGridViewCell> cells = selected.Cast <DataGridViewCell>();
                int minY = cells.Min(cell => cell.RowIndex);
                int maxY = cells.Max(cell => cell.RowIndex);
                result.A = cells.Where(cell => cell.RowIndex == minY).First();
                result.B = cells.Where(cell => cell.RowIndex == maxY).First();
                return(result);
            }

            if (this.SelectedRow(this.dataGrid.SelectedCells))
            {
                SmoothInfo result = new SmoothInfo();
                result.MinValue = min;
                result.MaxValue = max;
                IEnumerable <DataGridViewCell> cells = selected.Cast <DataGridViewCell>();
                int minX = cells.Min(cell => cell.ColumnIndex);
                int maxX = cells.Max(cell => cell.ColumnIndex);
                result.A = cells.Where(cell => cell.ColumnIndex == minX).First();
                result.B = cells.Where(cell => cell.ColumnIndex == maxX).First();
                return(result);
            }

            return(null);
        }
        private SmoothInfo GetSmoothInfo(double min, double max)
        {
            var selected = dataGrid.SelectedCells;

            if (SelectedColumn(selected))
            {
                var result = new SmoothInfo();
                result.MinValue = min;
                result.MaxValue = max;
                var cells = selected.Cast <DataGridViewCell>().ToList();

                var minY = cells.Min(cell => cell.RowIndex);
                var maxY = cells.Max(cell => cell.RowIndex);
                result.A = cells.First(cell => cell.RowIndex == minY);
                result.B = cells.First(cell => cell.RowIndex == maxY);
                return(result);
            }

            if (SelectedRow(dataGrid.SelectedCells))
            {
                var result = new SmoothInfo();
                result.MinValue = min;
                result.MaxValue = max;
                var cells = selected.Cast <DataGridViewCell>().ToList();

                var minX = cells.Min(cell => cell.ColumnIndex);
                var maxX = cells.Max(cell => cell.ColumnIndex);
                result.A = cells.First(cell => cell.ColumnIndex == minX);
                result.B = cells.First(cell => cell.ColumnIndex == maxX);
                return(result);
            }

            return(null);
        }
        private void DrawColumnSmooth(Graphics graphics, SmoothInfo si)
        {
            if (!TryGetValue(si.A.ColumnIndex, si.A.RowIndex, out var valueA))
            {
                return;
            }

            if (!TryGetValue(si.B.ColumnIndex, si.B.RowIndex, out var valueB))
            {
                return;
            }

            using (var pen = new Pen(Color.Blue, 3))
            {
                graphics.DrawLine(
                    pen,
                    GetColumnX(si.MinValue, si.MaxValue, valueA),
                    GetColumnY(si.A.RowIndex),
                    GetColumnX(si.MinValue, si.MaxValue, valueB),
                    GetColumnY(si.B.RowIndex));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Draw the side views that help visual=ize the table shape.
        /// </summary>
        private void DrawSideViews(int activeColumn, int activeRow)
        {
            Bitmap   horizontalPanelBitmap     = new Bitmap(this.horizontalPanel.Width, this.horizontalPanel.Height);
            Graphics horizontalPanelBackBuffer = Graphics.FromImage(horizontalPanelBitmap);
            //Graphics horizontalPanelBackBuffer = horizontalPanel.CreateGraphics();

            Bitmap   verticalPanelBitmap     = new Bitmap(this.verticalPanel.Width, this.verticalPanel.Height);
            Graphics verticalPanelBackBuffer = Graphics.FromImage(verticalPanelBitmap);

            //Graphics verticalPanelBackBuffer = verticalPanel.CreateGraphics();

            horizontalPanelBackBuffer.FillRectangle(Brushes.White, this.horizontalPanel.ClientRectangle);
            verticalPanelBackBuffer.FillRectangle(Brushes.White, this.verticalPanel.ClientRectangle);

            double min;
            double max;

            this.GetMinMax(out min, out max);

            Pen pen = Pens.Gray;

            for (int row = 0; row < this.dataGrid.Rows.Count; row++)
            {
                this.DrawRow(horizontalPanelBackBuffer, pen, row, min, max);
            }

            for (int column = 0; column < this.dataGrid.Columns.Count; column++)
            {
                this.DrawColumn(verticalPanelBackBuffer, pen, column, min, max);
            }

            if ((activeColumn >= 0) && (activeColumn < this.dataGrid.Columns.Count) &&
                (activeRow >= 0) && (activeRow < this.dataGrid.Rows.Count))
            {
                using (Pen heavyPen = new Pen(Color.Black, 3))
                {
                    this.DrawRow(horizontalPanelBackBuffer, heavyPen, activeRow, min, max);
                    this.DrawColumn(verticalPanelBackBuffer, heavyPen, activeColumn, min, max);
                }

                using (Pen lightPen = new Pen(Color.Gray, 2))
                {
                    int x = this.GetRowX(activeColumn);
                    horizontalPanelBackBuffer.DrawLine(lightPen, x, 0, x, horizontalPanel.Height);

                    int y = this.GetColumnY(activeRow);
                    verticalPanelBackBuffer.DrawLine(lightPen, 0, y, verticalPanel.Width, y);
                }
            }

            SmoothInfo si = this.GetSmoothInfo(min, max);

            if (si != null)
            {
                if (si.A.RowIndex == si.B.RowIndex)
                {
                    this.DrawRowSmooth(horizontalPanelBackBuffer, si);
                }
                else
                {
                    this.DrawColumnSmooth(verticalPanelBackBuffer, si);
                }
            }

            Graphics graphics = this.horizontalPanel.CreateGraphics();

            graphics.DrawImage(horizontalPanelBitmap, 0, 0);
            graphics = this.verticalPanel.CreateGraphics();
            graphics.DrawImage(verticalPanelBitmap, 0, 0);
        }