public void AttachArrayToProvideScaleFor(ArrayPlot AP) { this.CF = new ColorFunction(AP.GetColor); AP.NewGridLoaded += new newGridLoadedEvent(SetMatrixForPlotting); }
internal virtual void RecreateImage() { if (TheColoredSquaresBM != null) { TheColoredSquaresBM.Dispose(); TheColoredSquaresBM = null; } TheColoredSquaresBM = new System.Drawing.Bitmap(this.Width, this.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); MakeRectanglePostions(); Graphics g = Graphics.FromImage(TheColoredSquaresBM); g.Clear(System.Drawing.Color.White); SolidBrush BlackBrush = new SolidBrush(Color.Black); SolidBrush whiteBrush = new SolidBrush(Color.White); SolidBrush labelBrush = new SolidBrush(LabelTextColor); Pen P = new Pen(Color.Black, 2); try { if (DrawColLabels) { string[] Labels = Matrix.ColNames; if (Labels == null) { Labels = new string[Matrix.ColCount]; for (int i = 1; i <= Matrix.ColCount; i++) { Labels[i - 1] = i.ToString(); } } for (int i = 1; i <= Matrix.ColCount; i++) { g.DrawString(Labels[i - 1], this.Font, BlackBrush, ((float)(RoomForText + (ColSideLength * .25) + ColSideLength * (i - 1))), 0); } } if (DrawRowLabels) { string[] Rows = Matrix.RowNames; if (Rows == null) { Rows = new string[Matrix.RowCount]; for (int i = 1; i <= Matrix.RowCount; i++) { Rows[i - 1] = i.ToString(); } } for (int i = 0; i < Matrix.RowCount; i++) { g.DrawString(Rows[i].ToString(), this.Font, BlackBrush, 0, ((float)(RoomForText + (RowSideLength * .35) + RowSideLength * i))); } } int NumWells = Matrix.TotalElements; int NumCols = Matrix.ColCount; int[,] TextPos = new int[NumWells, 2]; Rectangle[] PlateWells = new Rectangle[NumWells]; double min = Matrix.MinValue; double max = Matrix.MaxValue; double[] DataToSquare = new double[NumWells]; for (int i = 0; i < NumWells; i++) { int ColPos = i % NumCols; int rowPos = Convert.ToInt32((i / NumCols)); double arrayValue = Matrix.Array[rowPos, ColPos]; DataToSquare[i] = arrayValue; Color col = GetColor(arrayValue, min, max); SolidBrush toPaintWith = new SolidBrush(col); int RecYPos = RowPositions[rowPos]; int RecXPos = ColumnPositions[ColPos]; TextPos[i, 0] = (int)(RecXPos + ColSideLength * .15); TextPos[i, 1] = (int)(RecYPos + (RowSideLength / 2) - (this.Font.Height / 2)); PlateWells[i] = new Rectangle(RecXPos, RecYPos, ColSideLength, RowSideLength); g.FillRectangle(toPaintWith, PlateWells[i]); toPaintWith.Dispose(); } g.DrawRectangles(P, PlateWells); if (pShowValues) { for (int i = 0; i < NumWells; i++) { double val = DataToSquare[i]; if (ArrayPlot.isReal(val)) { string toWrite = DataToSquare[i].ToString(LabelFormat); g.DrawString(toWrite, FontForLabels, labelBrush, TextPos[i, 0], TextPos[i, 1]); } } } } finally { g.Dispose(); BlackBrush.Dispose(); P.Dispose(); labelBrush.Dispose(); whiteBrush.Dispose(); this.Refresh(); } }