protected override void LoadExample() { // begin view init view.BeginInit(); // configure the view view.Grid.Visible = false; view.Selection.Mode = DiagramSelectionMode.Single; view.GlobalVisibility.ShowPorts = false; view.HorizontalRuler.Visible = false; view.VerticalRuler.Visible = false; // create two stylesheets - one for the vertices and one for the edges NStyleSheet vertexStyleSheet = new NStyleSheet(); vertexStyleSheet.Name = "Vertices"; vertexStyleSheet.Style.FillStyle = new NColorFillStyle(Color.FromArgb(236, 97, 49)); document.StyleSheets.AddChild(vertexStyleSheet); NStyleSheet edgeStyleSheet = new NStyleSheet(); edgeStyleSheet.Name = "Edges"; edgeStyleSheet.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(68, 90, 108)); document.StyleSheets.AddChild(edgeStyleSheet); // configure the graph data source importer m_GraphImporter = new NGraphDataSourceImporter(); // set the document in the active layer of which the shapes will be imported m_GraphImporter.Document = document; // set the data sources // the graph data source importer supports the following data sources // DataTable // DataView // OleDbDataAdapter // SqlDataAdapter // OdbcDataAdapter // OleDbCommand // SqlCommand // OdbcCommand // in this example we have created two OleDbDataAdapters: // the PagesDataAdapter selects all records and columns from the Pages table of the SiteMap.mdb // the LinksDataAdapter selects all records and columns from the Links table of the SiteMap.mdb oleDbConnection1.ConnectionString = @"Data Source=""" + Application.StartupPath + @"\..\..\Resources\Data\SiteMap.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";"; oleDbConnection2.ConnectionString = @"Data Source=""" + Application.StartupPath + @"\..\..\Resources\Data\SiteMap.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0"";"; m_GraphImporter.VertexDataSource = PagesDataAdapter; m_GraphImporter.EdgeDataSource = LinksDataAdapter; // vertex records are uniquely identified by their Id (in the Pages table) // edges link the vertices with the FromPageId and ToPageId (in the Links table) m_GraphImporter.VertexIdColumnName = "Id"; m_GraphImporter.FromVertexIdColumnName = "FromPageId"; m_GraphImporter.ToVertexIdColumnName = "ToPageId"; // create vertices as rectangles shapes, with default size (60, 30) NBasicShapesFactory shapesFactory = new NBasicShapesFactory(); shapesFactory.DefaultSize = new NSizeF(60, 30); m_GraphImporter.VertexShapesFactory = shapesFactory; m_GraphImporter.VertexShapesName = BasicShapes.Rectangle.ToString(); // set stylesheets to be applied to imported vertices and edges m_GraphImporter.VertexStyleSheetName = "Vertices"; m_GraphImporter.EdgeStyleSheetName = "Edges"; // use layered graph layout NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.Direction = LayoutDirection.LeftToRight; layout.LayerAlignment = RelativeAlignment.Near; m_GraphImporter.Layout = layout; // subscribe for the vertex imported event, // which is raised when a shape was created for a data source record m_GraphImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported); // import m_GraphImporter.Import(); // end view init view.EndInit(); }
private void ImportData() { NDrawingDocument document = NDrawingView1.Document; document.BackgroundStyle.FrameStyle.Visible = false; // create two stylesheets - one for the vertices and one for the edges NStyleSheet vertexStyleSheet = new NStyleSheet(); vertexStyleSheet.Name = "Vertices"; NStyle.SetFillStyle(vertexStyleSheet, new NColorFillStyle(Color.FromArgb(236, 97, 49))); document.StyleSheets.AddChild(vertexStyleSheet); NStyleSheet edgeStyleSheet = new NStyleSheet(); edgeStyleSheet.Name = "Edges"; NStyle.SetStrokeStyle(edgeStyleSheet, new NStrokeStyle(Color.Blue)); NStyle.SetEndArrowheadStyle(edgeStyleSheet, new NArrowheadStyle(ArrowheadShape.OpenedArrow, null, new NSizeL(6, 4), null, new NStrokeStyle(Color.Blue))); NTextStyle textStyle = (NTextStyle)document.ComposeTextStyle().Clone(); textStyle.StringFormatStyle.VertAlign = Nevron.VertAlign.Bottom; NStyle.SetTextStyle(edgeStyleSheet, textStyle); document.StyleSheets.AddChild(edgeStyleSheet); // create the graph data source importer NGraphDataSourceImporter graphImporter = new NGraphDataSourceImporter(); // set the document in the active layer of which the shapes will be imported graphImporter.Document = document; // SET THE DATA SOURCE // the tree data source importer supports the following data sources // DataTable // DataView // OleDbDataAdapter // SqlDataAdapter // OdbcDataAdapter // OleDbCommand // SqlCommand // OdbcCommand // in this example we have created an OleDbDataAdapter, // which selects all columns and records from the Sources and Links tables of the Data.xlsx file string databasePath = Server.MapPath(@"..\Examples\Import\Data.xlsx"); string connectionString = @"Data Source=""" + databasePath + @""";Provider=""Microsoft.ACE.OLEDB.12.0""; Extended Properties=""Excel 12.0 Xml;HDR=YES"";"; graphImporter.VertexDataSource = new OleDbDataAdapter("SELECT * FROM [Sources$]", connectionString); graphImporter.EdgeDataSource = new OleDbDataAdapter("SELECT * FROM [Links$]", connectionString); // vertex records are uniquely identified by their Id (in the Sources table) // edges link the vertices with the Fro and ToPageId (in the Links table) graphImporter.VertexIdColumnName = "Id"; graphImporter.FromVertexIdColumnName = "From"; graphImporter.ToVertexIdColumnName = "To"; // create vertices as group shapes, with default size NShapesFactory shapesFactory = new GroupShapesFactory(); shapesFactory.DefaultSize = VertexSize; graphImporter.VertexShapesFactory = shapesFactory; graphImporter.VertexShapesName = GroupShapes.Group.ToString(); // set stylesheets to be applied to imported vertices and edges graphImporter.VertexStyleSheetName = "Vertices"; graphImporter.EdgeStyleSheetName = "Edges"; // use layered graph layout NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.LayerSpacing = 70; layout.Direction = LayoutDirection.LeftToRight; layout.LayerAlignment = RelativeAlignment.Near; graphImporter.Layout = layout; // subscribe for the vertex and edge imported events, // which are raised when a shape was created for a data source record graphImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported); graphImporter.EdgeImported += new ShapeImportedDelegate(OnEdgeImported); // import graphImporter.Import(); }
private void InitDocument() { NDrawingDocument document = NDrawingView1.Document; document.BackgroundStyle.FrameStyle.Visible = false; // create two stylesheets - one for the vertices and one for the edges NStyleSheet vertexStyleSheet = new NStyleSheet(); vertexStyleSheet.Name = "Vertices"; vertexStyleSheet.Style.FillStyle = new NColorFillStyle(Color.FromArgb(236, 97, 49)); document.StyleSheets.AddChild(vertexStyleSheet); NStyleSheet edgeStyleSheet = new NStyleSheet(); edgeStyleSheet.Name = "Edges"; edgeStyleSheet.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(68, 90, 108)); document.StyleSheets.AddChild(edgeStyleSheet); // create the tree data source importer NGraphDataSourceImporter graphImporter = new NGraphDataSourceImporter(); // set the document in the active layer of which the shapes will be imported graphImporter.Document = document; // SET THE DATA SOURCE // the tree data source importer supports the following data sources // DataTable // DataView // OleDbDataAdapter // SqlDataAdapter // OdbcDataAdapter // OleDbCommand // SqlCommand // OdbcCommand // in this example we have created an OleDbDataAdapter, // which selects all columns and records from the Pages table of the SiteMap.mdb string databasePath = HttpContext.Current.Server.MapPath(@"..\App_Data\SiteMap.xml"); DataSet dataSet = new DataSet(); dataSet.ReadXml(databasePath, XmlReadMode.ReadSchema); graphImporter.VertexDataSource = dataSet.Tables["Pages"]; graphImporter.EdgeDataSource = dataSet.Tables["Links"]; // vertex records are uniquely identified by their Id (in the Pages table) // edges link the vertices with the FromPageId and ToPageId (in the Links table) graphImporter.VertexIdColumnName = "Id"; graphImporter.FromVertexIdColumnName = "FromPageId"; graphImporter.ToVertexIdColumnName = "ToPageId"; // create vertices as rectangles shapes, with default size (60,30) NBasicShapesFactory shapesFactory = new NBasicShapesFactory(); shapesFactory.DefaultSize = new NSizeF(60, 30); graphImporter.VertexShapesFactory = shapesFactory; graphImporter.VertexShapesName = BasicShapes.Rectangle.ToString(); // set stylesheets to be applied to imported vertices and edges graphImporter.VertexStyleSheetName = "Vertices"; graphImporter.EdgeStyleSheetName = "Edges"; // use layered graph layout NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.Direction = LayoutDirection.LeftToRight; layout.LayerAlignment = RelativeAlignment.Near; graphImporter.Layout = layout; // subscribe for the vertex imported event, // which is raised when a shape was created for a data source record graphImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported); // import graphImporter.Import(); }