Beispiel #1
0
 public void RemoveColumn(int column)
 {
     foreach (var val in _values)
     {
         val.RemoveAt(column);
     }
     XLabels.RemoveAt(column);
 }
        private void XYLineChartNodeModel_PortDisconnected(PortModel port)
        {
            // Clear UI when a input port is disconnected
            if (port.PortType == PortType.Input && this.State == ElementState.Active)
            {
                XLabels.Clear();
                YLabels.Clear();
                Values.Clear();
                Colors.Clear();

                RaisePropertyChanged("DataUpdated");
            }
        }
Beispiel #3
0
        public System.Drawing.Bitmap DrawBarColumn()
        {
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image)) {
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.Clear(System.Drawing.Color.Transparent);
                int     xCount    = 0;
                float   yCount    = 10F;
                decimal yMaxValue = 0M;

                xCount = XLabels.Count;

                Lines.ForEach(p => {
                    if (!IsSingleLine)
                    {
                        int?p10 = LinqHelper.Max(p.Points, p1 => (int?)p1.X);
                        if (p10 != null && p10 > xCount)
                        {
                            xCount = p10.Value;
                        }
                    }
                    decimal?p11 = LinqHelper.Max(p.Points, p1 => (decimal?)p1.Value);
                    if (p11 != null && p11 > yMaxValue)
                    {
                        yMaxValue = p11.Value;
                    }
                });
                System.Drawing.Font font = Font;

                float xStart = 50F;
                float xEnd   = Width - 15F;
                float xWidth = xEnd - xStart;
                float xUnit  = xWidth / xCount;

                float   yStart         = 20F;
                float   yEnd           = Height - font.Height * 2 - 10 - 20F;
                float   yHeight        = yEnd - yStart;
                float   yUnit          = yHeight / yCount;
                decimal yMaxValueRange = GetYMax(yMaxValue);
                decimal yValuePercent  = ((decimal)(yHeight - 2F) / yMaxValueRange);

                //x line
                System.Drawing.Pen xPen = new System.Drawing.Pen(System.Drawing.Brushes.Black, 1F);
                g.DrawLine(xPen, xStart, yEnd, xEnd, yEnd);
                //x points
                float xLinePointOffset = xStart;
                float XLineUnit        = xUnit / 2F;
                for (int i = 0; i <= xCount; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }
                    xLinePointOffset += XLineUnit;
                    g.DrawLine(xPen, xLinePointOffset, yEnd, xLinePointOffset, yEnd + 5);

                    LineXLabel           label      = XLabels.Find(p => p.X == i);
                    string               xLabel     = label.Name;
                    System.Drawing.SizeF xLabelSize = g.MeasureString(xLabel, font);
                    float xLabelX = xLinePointOffset - xLabelSize.Width / 2;
                    label.RealX = xLinePointOffset - xLabelSize.Width / 2;
                    label.RealY = yEnd + 8;
                    label.AbsX  = xLinePointOffset;
                    System.Drawing.Brush brush = System.Drawing.Brushes.Black;
                    if (label.LineIndex != -1)
                    {
                        brush = _lines[label.LineIndex].TextBrush;
                    }
                    g.DrawString(xLabel, font, brush, label.RealX, label.RealY);

                    xLinePointOffset += XLineUnit;
                }

                //y line
                g.DrawLine(xPen, xStart, yEnd, xStart, yStart);
                //y points
                float yLinePointOffset = yEnd;
                for (int i = 0; i <= yCount; i++)
                {
                    g.DrawLine(xPen, xStart - 5, yLinePointOffset, xStart, yLinePointOffset);
                    //g.DrawLine(xPen, xStart - 5, i == 0 ? yLinePointOffset - 2F : yLinePointOffset, xStart, i == 0 ? yLinePointOffset - 2F : yLinePointOffset);

                    string yLabel = NumberToString((yMaxValueRange * i / 10));
                    System.Drawing.SizeF yLabelSize = g.MeasureString(yLabel, NumberFont);
                    float yLabelY = yLinePointOffset - yLabelSize.Height / 2;
                    float yLabelX = xStart - 5 - 3 - yLabelSize.Width;
                    g.DrawString(yLabel, NumberFont, System.Drawing.Brushes.Black, yLabelX, yLabelY);

                    yLinePointOffset -= yUnit;
                }
                //point-lines

                float pointWidth        = (xUnit - 6F) / (IsSingleLine ? 1 : Lines.Count);
                float lineNameXOffset   = xStart;
                float lineNameY         = Height - 10 - Font.Height;
                float pointTextMaxWidth = System.Math.Max(pointWidth / 2F, pointWidth - 10F);
                for (int i = 0; i < Lines.Count; i++)
                {
                    Line line = Lines[i];
                    //float lastX = xStart;
                    //float lastY = yEnd;
                    float xPointOffset = xStart;

                    //line name
                    g.FillRectangle(line.TextBrush, lineNameXOffset, lineNameY, Font.Height, Font.Height);
                    lineNameXOffset += Font.Height + 3F;
                    System.Drawing.SizeF lineNameSize = g.MeasureString(line.Name, Font);
                    g.DrawString(line.Name, Font, line.TextBrush, lineNameXOffset, lineNameY + (Font.Height - lineNameSize.Height) / 2F);
                    lineNameXOffset += lineNameSize.Width + 10F;
                    if (!string.IsNullOrEmpty(line.Value))
                    {
                        lineNameXOffset -= 8F;
                        System.Drawing.SizeF lineValueSize = g.MeasureString(line.Value, Font);
                        g.DrawString(line.Value, Font, line.TextBrush, lineNameXOffset, lineNameY + (Font.Height - lineValueSize.Height) / 2F);
                        lineNameXOffset += lineValueSize.Width + 10F;
                    }
                    for (int j = 1; j <= xCount; j++)
                    {
                        LinePoint item = line.Points.Find(p => p.X == j);
                        if (item != null)
                        {
                            LineXLabel label = XLabels.Find(p => p.X == item.X);
                            //y by value percent
                            float pointHeight = (float)(item.Value * yValuePercent);
                            if (pointHeight >= 1F)
                            {
                                float pointY = yEnd - 1F - pointHeight;
                                //float pointY = yEnd - 2F - pointHeight;
                                float pointX = xPointOffset + 3F + (IsSingleLine ? 0F : pointWidth * i);

                                //new System.Drawing.Drawing2D.LinearGradientBrush(
                                g.FillRectangle(new System.Drawing.SolidBrush(line.Color), pointX, pointY, pointWidth, pointHeight);
                                //cires r-3
                                //text value, to y
                                string pointText = NumberToString(item.Value);
                                if (pointText != "0")
                                {
                                    System.Drawing.SizeF pointTextSize = g.MeasureString(pointText, NumberFont);
                                    g.DrawString(pointText, NumberFont, line.TextBrush, pointX + ((pointWidth - pointTextSize.Width) / 2F), pointY - Font.Height - 3F);
                                }
                            }
                        }
                        xPointOffset += xUnit;
                    }
                    //foreach (LinePoint item in line.Points) {
                    //    LineXLabel label = XLabels.Find(p => p.X == item.X);
                    //    //y by value percent
                    //    float pointHeight = (float)(item.Value * yValuePercent);
                    //    if (pointHeight < 1F)
                    //        pointHeight = 1F;
                    //    float pointY = yEnd - 2F - pointHeight;
                    //    float pointX = xPointOffset + 3F + (IsSingleLine ? 0F : pointWidth * i);

                    //    //new System.Drawing.Drawing2D.LinearGradientBrush(
                    //    g.FillRectangle(new System.Drawing.SolidBrush(line.Color), pointX, pointY, pointWidth, pointHeight);
                    //    //cires r-3
                    //    //text value, to y
                    //    string pointText = NumberToString(item.Value);
                    //    if (pointText != "0") {
                    //        System.Drawing.SizeF pointTextSize = g.MeasureString(pointText, NumberFont);
                    //        g.DrawString(pointText, NumberFont, line.TextBrush, pointX + ((pointWidth - pointTextSize.Width) / 2F), pointY - Font.Height - 3F);
                    //    }

                    //    xPointOffset += xUnit;
                    //}
                }
            }

            return(image);
        }