/// <summary>Positions and refreshes all controls.</summary> private void PositionAndRefreshControls() { this.Resize -= OnResize; int numControls = Controls.Count; if (numControls > 0) { int numCols = 2; int numRows; if (numControls == 1) { numCols = 1; numRows = 1; } else { numCols = 2; numRows = (int)Math.Ceiling((double)numControls / numCols); } int width = (Size.Width - 50) / numCols; int height = Size.Height / numRows - 1; if (height < Size.Height / 2) { height = Size.Height / 2; AutoScroll = true; VScroll = true; } int controlNumber = 0; int col = 0; int row = 0; foreach (Control control in Controls) { GraphView graphView = control as GraphView; if (graphView != null) { graphView.FontSize = 10; graphView.Refresh(); graphView.SingleClick += OnGraphClick; graphView.IsLegendVisible = false; } control.Location = new Point(col * width, row * height); control.Width = width; control.Height = height; controlNumber++; col++; if (col >= numCols) { col = 0; row++; } } } this.Resize += OnResize; }
/// <summary>User has double clicked a graph.</summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnGraphClick(object sender, EventArgs e) { GraphView graphView = sender as GraphView; if (graphView != null) { graphView.IsLegendVisible = !graphView.IsLegendVisible; graphView.Refresh(); } }
/// <summary>User has double clicked a graph.</summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnGraphClick(object sender, EventArgs e) { try { GraphView graphView = sender as GraphView; if (graphView != null) { graphView.IsLegendVisible = !graphView.IsLegendVisible; graphView.Refresh(); } } catch (Exception err) { ShowError(err); } }
/// <summary>Creates the graph.</summary> /// <param name="writer">The writer.</param> /// <param name="graphAndTable">The graph and table to convert to html.</param> /// <param name="workingDirectory">The working directory.</param> private void CreateGraphPDF(Section section, AutoDocumentation.GraphAndTable graphAndTable, string workingDirectory) { // Create a 2 column, 1 row table. Image in first cell, X/Y data in second cell. Table table = section.AddTable(); table.Style = "GraphAndTable"; table.Rows.LeftIndent = graphAndTable.indent + "cm"; Column column1 = table.AddColumn(); column1.Width = "8cm"; //column1.Format.Alignment = ParagraphAlignment.Right; Column column2 = table.AddColumn(); column2.Width = "8cm"; //column2.Format.Alignment = ParagraphAlignment.Right; Row row = table.AddRow(); // Ensure graphs directory exists. string graphDirectory = Path.Combine(workingDirectory, "Graphs"); Directory.CreateDirectory(graphDirectory); // Determine the name of the .png file to write. string PNGFileName = Path.Combine(graphDirectory, graphAndTable.xyPairs.Parent.Parent.Name + graphAndTable.xyPairs.Parent.Name + ".png"); // Setup graph. GraphView graph = new GraphView(); graph.Clear(); // Create a line series. graph.DrawLineAndMarkers("", graphAndTable.xyPairs.X, graphAndTable.xyPairs.Y, Models.Graph.Axis.AxisType.Bottom, Models.Graph.Axis.AxisType.Left, System.Drawing.Color.Blue, Models.Graph.LineType.Solid, Models.Graph.MarkerType.None, Models.Graph.LineThicknessType.Normal, Models.Graph.MarkerSizeType.Normal, true); // Format the axes. graph.FormatAxis(Models.Graph.Axis.AxisType.Bottom, graphAndTable.xName, false, double.NaN, double.NaN, double.NaN); graph.FormatAxis(Models.Graph.Axis.AxisType.Left, graphAndTable.yName, false, double.NaN, double.NaN, double.NaN); graph.BackColor = System.Drawing.Color.White; graph.FontSize = 10; graph.Refresh(); // Export graph to bitmap file. Bitmap image = new Bitmap(400, 250); graph.Export(image, false); image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png); MigraDoc.DocumentObjectModel.Shapes.Image image1 = row.Cells[0].AddImage(PNGFileName); // Add x/y data. Paragraph xyParagraph = row.Cells[1].AddParagraph(); xyParagraph.Style = "xyStyle"; AddFixedWidthText(xyParagraph, "X", 10); AddFixedWidthText(xyParagraph, "Y", 10); xyParagraph.AddLineBreak(); for (int i = 0; i < graphAndTable.xyPairs.X.Length; i++) { AddFixedWidthText(xyParagraph, graphAndTable.xyPairs.X[i].ToString(), 10); AddFixedWidthText(xyParagraph, graphAndTable.xyPairs.Y[i].ToString(), 10); xyParagraph.AddLineBreak(); } // Add an empty paragraph for spacing. Paragraph spacing = section.AddParagraph(); }