private void CreateTextShape(ref NShape shape) { shape = new NRectangleShape(0, 0, SEAT_SIZE.Width * 10, SEAT_SIZE.Height); NStyle.SetFillStyle(shape, new NColorFillStyle(Color.White)); NStyle.SetStrokeStyle(shape, new NStrokeStyle(0, Color.White)); NStyle.SetTextStyle(shape, new NTextStyle()); shape.Style.TextStyle.StringFormatStyle = new NStringFormatStyle(StringFormatType.GenericTypographic, HorzAlign.Left, VertAlign.Center); SetProtections(shape); document.ActiveLayer.AddChild(shape); }
public void InitDocument(NDrawingDocument document, NDataGrouping dataGrouping) { // Configure the drawing document document.Layers.RemoveAllChildren(); document.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108)); document.RoutingManager.Enabled = false; document.BridgeManager.Enabled = false; document.Bounds = new NRectangleF(0, 0, 5000, 5000); document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.LightBlue); // Add a style sheet NStyleSheet styleSheet = new NStyleSheet(WhiteTextStyleSheetName); NTextStyle textStyle = (NTextStyle)document.ComposeTextStyle().Clone(); textStyle.FillStyle = new NColorFillStyle(KnownArgbColorValue.White); NStyle.SetTextStyle(styleSheet, textStyle); document.StyleSheets.AddChild(styleSheet); // Create a map importer NEsriMapImporter mapImporter = new NEsriMapImporter(); mapImporter.MapBounds = NMapBounds.World; // Add a shapefile NEsriShapefile countries = new NEsriShapefile(HttpContext.Current.Server.MapPath(CountriesShapefileName)); countries.NameColumn = "NAME"; countries.TextColumn = "NAME"; mapImporter.AddLayer(countries); // Read the map data mapImporter.Read(); // Create a fill rule NMapFillRuleRange fillRule = new NMapFillRuleRange("POP_1994", Color.White, Color.Black, 12); fillRule.DataGrouping = dataGrouping; countries.FillRule = fillRule; // Associate a shape created listener and import the map data mapImporter.ShapeCreatedListener = new NCustomShapeCreatedListener(); mapImporter.Import(document, document.Bounds); // Generate a legend NMapLegendRange mapLegend = (NMapLegendRange)mapImporter.GetLegend(fillRule); mapLegend.Title = "Population (thousands people)"; mapLegend.RangeFormatString = "{0:#,###,##0,} - {1:#,###,##0,}"; mapLegend.LastFormatString = "more than {0:#,###,##0,}"; NMapLegendRenderPage.MapLegend = mapLegend; document.SizeToContent(); }
private void CreateStyleSheets(NDrawingDocument document) { // Create the zoomed city style sheet NStyleSheet zoomedCity = new NStyleSheet(); zoomedCity.Name = "ZoomedCity"; NTextStyle textStyle = (NTextStyle)document.ComposeTextStyle().Clone(); textStyle.FontStyle = new NFontStyle(textStyle.FontStyle.Name, textStyle.FontStyle.EmSize, FontStyle.Bold); NStyle.SetTextStyle(zoomedCity, textStyle); NStyle.SetFillStyle(zoomedCity, new NColorFillStyle(Color.Red)); document.StyleSheets.AddChild(zoomedCity); }
/// <summary> /// Shows the text style edtior for the specified styleable node /// </summary> /// <param name="styleable"></param> protected void ShowTextStyleEditor(INStyleable styleable) { if (styleable == null) { return; } NTextStyle textStyle = styleable.ComposeTextStyle(); NTextStyle newTextStyle = null; if (NTextStyleTypeEditor.Edit(textStyle, textStyle != NStyle.GetTextStyle(styleable), out newTextStyle)) { NStyle.SetTextStyle(styleable, newTextStyle); document.SmartRefreshAllViews(); } }
public void InitDocument(NDrawingDocument document) { // Set up visual formatting document.BackgroundStyle.FrameStyle.Visible = false; document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.LightBlue); document.GraphicsSettings.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; // Create style sheets NStyleSheet clickedCounty = new NStyleSheet("ClickedCounty"); NStyle.SetFillStyle(clickedCounty, new NColorFillStyle(KnownArgbColorValue.Red)); NStyle.SetTextStyle(clickedCounty, new NTextStyle(document.ComposeTextStyle().FontStyle, Color.White)); document.StyleSheets.AddChild(clickedCounty); // Load the map of the USA LoadUsaMap(document); }
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(); }
protected NCompositeShape CreateOrgChartShape(NPersonalInfo info) { NRectangleF bounds = info.Bounds; float bottomPortAlignment = info.BottomPortAlignment; Bitmap photo = new Bitmap(this.MapPathSecure(info.Picture)); // compose a new graph vertex from a frame and an image NRectanglePath frame = new NRectanglePath(bounds); NRectanglePath image = new NRectanglePath(new NPointF(bounds.X + 5, bounds.Y + 5), new NSizeF(photo.Size)); NImageFillStyle imgageFillStyle = new NImageFillStyle(photo, 0xff); NStyle.SetFillStyle(image, imgageFillStyle); NCompositeShape shape = new NCompositeShape(); shape.Primitives.AddChild(frame); shape.Primitives.AddChild(image); shape.UpdateModelBounds(); Document.ActiveLayer.AddChild(shape); // set the vertex fill style NColorFillStyle fillStyle = null; switch (info.Level) { case 0: fillStyle = new NColorFillStyle(Color.FromArgb(241, 100, 34)); break; case 1: fillStyle = new NColorFillStyle(Color.FromArgb(249, 167, 26)); break; case 2: fillStyle = new NColorFillStyle(Color.FromArgb(255, 247, 151)); break; } fillStyle.ImageFiltersStyle.Filters.Add(new NLightingImageFilter()); shape.Style.FillStyle = fillStyle; NInteractivityStyle interactivityStyle = new NInteractivityStyle(); interactivityStyle.Tooltip.Text = "Click to show " + info.Name + " personal information"; interactivityStyle.UrlLink.Url = "../Examples/WebControl/GettingStarted/NPersonalInfoPage.aspx?" + info.Id.ToString(); shape.Style.InteractivityStyle = interactivityStyle; // add a new label for the person name NRotatedBoundsLabel nameLabel = new NRotatedBoundsLabel(info.Name, shape.UniqueId, new Nevron.Diagram.NMargins(40, 1, 50, 1)); shape.Labels.AddChild(nameLabel); NStyle.SetTextStyle(nameLabel, nameLabel.ComposeTextStyle().Clone() as NTextStyle); nameLabel.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; nameLabel.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Top; // configure default label (used for the person position) NRotatedBoundsLabel positionLabel = shape.Labels.DefaultLabel as NRotatedBoundsLabel; NStyle.SetTextStyle(positionLabel, positionLabel.ComposeTextStyle().Clone() as NTextStyle); positionLabel.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial", 10, FontStyle.Bold)); positionLabel.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; positionLabel.Style.TextStyle.StringFormatStyle.VertAlign = VertAlign.Bottom; positionLabel.Margins = new Nevron.Diagram.NMargins(40, 5, 1, 50); positionLabel.Text = info.Position; // create the optional ports of the shape shape.CreateShapeElements(ShapeElementsMask.Ports); // add rotated bounds ports NPort leftPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.MiddleLeft)); leftPort.Name = "Left"; shape.Ports.AddChild(leftPort); NPort rightPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.MiddleRight)); rightPort.Name = "Right"; shape.Ports.AddChild(rightPort); NPort topPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(ContentAlignment.TopCenter)); topPort.Name = "Top"; shape.Ports.AddChild(topPort); NRotatedBoundsPort bottomPort = new NRotatedBoundsPort(shape.UniqueId, new NContentAlignment(bottomPortAlignment, 50)); bottomPort.Name = "Bottom"; shape.Ports.AddChild(bottomPort); return(shape); }
private void InitDocument() { // create a rectangle shape with a 2 bounds label NShape shape = new NRectangleShape(base.GetGridCell(0, 0)); shape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 0xcc, 0, 0)); shape.Labels.RemoveAllChildren(); NBoundsLabel boundsLabel = new NBoundsLabel("Label 1, Wrapped", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 0, 50)); shape.Labels.AddChild(boundsLabel); shape.Labels.DefaultLabelUniqueId = boundsLabel.UniqueId; boundsLabel = new NBoundsLabel("Label 2, Stretched", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 50, 0)); boundsLabel.Mode = BoxTextMode.Stretch; shape.Labels.AddChild(boundsLabel); document.ActiveLayer.AddChild(shape); // create a rectangle shape with a 2 rotated bounds labels shape = new NRectangleShape(base.GetGridCell(0, 1)); shape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(50, 0, 0, 0xcc)); shape.Labels.RemoveAllChildren(); NRotatedBoundsLabel rotatedLabel = new NRotatedBoundsLabel("Rotated Label 1, Wrapped", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 0, 50)); shape.Labels.AddChild(rotatedLabel); shape.Labels.DefaultLabelUniqueId = rotatedLabel.UniqueId; rotatedLabel = new NRotatedBoundsLabel("Rotated Label 2, Stretched", shape.UniqueId, new Nevron.Diagram.NMargins(0, 0, 50, 0)); rotatedLabel.Mode = BoxTextMode.Stretch; shape.Labels.AddChild(rotatedLabel); document.ActiveLayer.AddChild(shape); // create a polyline shape with two logical line labels NRectangleF cell = base.GetGridCell(1, 0, 0, 1); shape = new NPolylineShape(new NPointF[] { cell.Location, cell.RightBottom }); shape.Labels.RemoveAllChildren(); NLogicalLineLabel lineLabel = new NLogicalLineLabel("Line label - start", shape.UniqueId, 0, true, true); shape.Labels.AddChild(lineLabel); shape.Labels.DefaultLabelUniqueId = lineLabel.UniqueId; // alter the start label text style NTextStyle textStyle = document.Style.TextStyle.Clone() as NTextStyle; textStyle.StringFormatStyle.HorzAlign = HorzAlign.Left; textStyle.Offset = new NPointL(0, -7); NStyle.SetTextStyle(lineLabel, textStyle); // add the end label lineLabel = new NLogicalLineLabel("Line label - end", shape.UniqueId, 100, true, true); shape.Labels.AddChild(lineLabel); // alter the end label text style textStyle = document.Style.TextStyle.Clone() as NTextStyle; textStyle.StringFormatStyle.HorzAlign = HorzAlign.Right; textStyle.Offset = new NPointL(0, -7); NStyle.SetTextStyle(lineLabel, textStyle); document.ActiveLayer.AddChild(shape); }
protected void NDrawingView1_AsyncClick(object sender, EventArgs e) { NCallbackMouseEventArgs args = e as NCallbackMouseEventArgs; NNodeList nodes = NDrawingView1.HitTest(args); NNodeList shapes = nodes.Filter(CELL_FILTER); if (shapes.Count == 0) { return; } NTableCell cell = (NTableCell)shapes[0]; if (cell.ParentNode.ParentNode != table) { return; } if (cell.StyleSheetName != null && cell.StyleSheetName != string.Empty) { if (CellClicked(cell)) { UpdateInfo(); // Check for end of the game string status = string.Empty; if (AllClear()) { score *= 2; status = "You've cleared all cells !!!" + Environment.NewLine; } if (status == string.Empty && GameOver()) { status = "Game Over !" + Environment.NewLine; } if (status != string.Empty) { status += "Your score is " + score.ToString(); NTableShape gameOver = new NTableShape(); document.ActiveLayer.AddChild(gameOver); gameOver.BeginUpdate(); gameOver.CellPadding = new Nevron.Diagram.NMargins(2, 2, 8, 8); gameOver[0, 0].Text = status; NStyle.SetFillStyle(gameOver, new NAdvancedGradientFillStyle(AdvancedGradientScheme.Ocean1, 0)); NStyle.SetStrokeStyle(gameOver, new NStrokeStyle(Color.DarkBlue)); NTextStyle textStyle = (NTextStyle)table.ComposeTextStyle().Clone(); textStyle.FillStyle = new NColorFillStyle(Color.DarkBlue); NStyle.SetTextStyle(gameOver, textStyle); gameOver.EndUpdate(); gameOver.Center = table.Center; } } } }
/// <summary> /// Clears all highlighted cells. /// </summary> public void ClearHighlightedCells() { int cellCount = m_CellsToClear.Count; if (cellCount == 0) { return; } string colorString = BoardShape[m_CellsToClear[0].X, m_CellsToClear[0].Y].StyleSheetName; colorString = colorString.Remove(colorString.Length - HighlightedSuffix.Length); CellCount[IndexOf(colorString)] -= cellCount; Score += cellCount * cellCount; for (int i = 0; i < cellCount; i++) { NPoint p = m_CellsToClear[i]; BoardShape[p.X, p.Y].StyleSheetName = String.Empty; } // Apply gravity ApplyGravity(); // Update the cell count info UpdateInfo(); // Clear the cells to clear list m_CellsToClear.Clear(); // Check for end of the game string status = String.Empty; if (AllClear()) { Score *= 2; status = "You've cleared all cells !!!" + Environment.NewLine; } if (status == String.Empty && GameOver()) { status = "Game Over !" + Environment.NewLine; } if (status != String.Empty) { status += "Your score is " + Score.ToString(); NTableShape gameOver = new NTableShape(); ((NDrawingDocument)BoardShape.Document).ActiveLayer.AddChild(gameOver); gameOver.BeginUpdate(); gameOver.CellPadding = new Nevron.Diagram.NMargins(2, 2, 8, 8); gameOver[0, 0].Text = status; NStyle.SetFillStyle(gameOver, new NAdvancedGradientFillStyle(AdvancedGradientScheme.Mahogany2, 5)); NTextStyle textStyle = (NTextStyle)InfoShape.ComposeTextStyle().Clone(); textStyle.FillStyle = new NColorFillStyle(Color.White); NStyle.SetTextStyle(gameOver, textStyle); gameOver.EndUpdate(); gameOver.Center = BoardShape.Center; } }
private void InitDocument() { Bitmap bitmap = NResourceHelper.BitmapFromResource(GetType(), "Airplane.png", "Nevron.Examples.Diagram.WinForm.Resources"); document.Width = bitmap.Width; document.Height = bitmap.Height + 62; document.BackgroundStyle.FillStyle = new NImageFillStyle(bitmap); // Create the style sheets NStyleSheet free = new NStyleSheet("free"); NStyle.SetInteractivityStyle(free, new NInteractivityStyle(string.Empty, CursorType.Hand)); NStyle.SetFillStyle(free, new NColorFillStyle(SEAT_COLOR)); NStyle.SetStrokeStyle(free, new NStrokeStyle(1, Color.Black)); NStyle.SetTextStyle(free, new NTextStyle(new Font(view.Font, FontStyle.Bold), Color.Blue)); document.StyleSheets.AddChild(free); NStyleSheet reserved = new NStyleSheet("reserved"); NHatchFillStyle hatch = new NHatchFillStyle(HatchStyle.LightUpwardDiagonal, Color.Red, SEAT_COLOR); hatch.TextureMappingStyle.MapMode = MapMode.RelativeToViewer; NStyle.SetFillStyle(reserved, hatch); NStyle.SetStrokeStyle(reserved, new NStrokeStyle(1, Color.Black)); document.StyleSheets.AddChild(reserved); float x, y; float distance = DISTANCE; NShape shape; Point startPoint = LINE1_LEFT; m_Seats = new List <NShape>(); // Draw the seats for (y = LINE1_LEFT.Y; y < 350; y += SEAT_SIZE.Height) { if (y > 260 && y < LINE2_LEFT.Y) { y = LINE2_LEFT.Y; startPoint = LINE2_LEFT; } if (y >= LINE2_LEFT.Y) { distance = 5.25f; } for (x = startPoint.X; x < 970; x += SEAT_SIZE.Width + distance) { if (x > 460 && x < LINE1_RIGHT.X) { x = LINE1_RIGHT.X; distance = DISTANCE; } m_nFreeSeats++; shape = new NRectangleShape(x, y, SEAT_SIZE.Width, SEAT_SIZE.Height); shape.StyleSheetName = "free"; SetProtections(shape); document.ActiveLayer.AddChild(shape); m_Seats.Add(shape); } } // Free seats shape = new NRectangleShape(MARGINS, MARGINS, SEAT_SIZE.Width, SEAT_SIZE.Height); shape.StyleSheetName = "free"; SetProtections(shape); document.ActiveLayer.AddChild(shape); CreateTextShape(ref m_FreeSeats); m_FreeSeats.Location = new NPointF(shape.Bounds.Right + MARGINS, shape.Bounds.Y); // Reserved seats shape = new NRectangleShape(MARGINS, 2 * MARGINS + SEAT_SIZE.Height, SEAT_SIZE.Width, SEAT_SIZE.Height); shape.StyleSheetName = "reserved"; SetProtections(shape); document.ActiveLayer.AddChild(shape); CreateTextShape(ref m_ReservedSeats); m_ReservedSeats.Location = new NPointF(shape.Bounds.Right + MARGINS, shape.Bounds.Y); // Total revenue CreateTextShape(ref m_Revenue); m_Revenue.Location = new NPointF(shape.Bounds.Right + MARGINS, shape.Bounds.Bottom + MARGINS); m_Revenue.Style.TextStyle.FontStyle.Style = FontStyle.Bold; m_Revenue.Style.TextStyle.FillStyle = new NColorFillStyle(Color.MediumBlue); UpdateTexts(); }
private void InitDocument() { document.Layers.RemoveAllChildren(); // Configure the drawing document document.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(68, 90, 108)); document.RoutingManager.Enabled = false; document.BridgeManager.Enabled = false; document.Bounds = new NRectangleF(0, 0, 10000, 10000); document.BackgroundStyle.FillStyle = new NColorFillStyle(Color.LightBlue); // Add a style sheet NStyleSheet styleSheet = new NStyleSheet(WhiteTextStyleSheetName); NTextStyle textStyle = (NTextStyle)document.ComposeTextStyle().Clone(); textStyle.FillStyle = new NColorFillStyle(KnownArgbColorValue.White); NStyle.SetTextStyle(styleSheet, textStyle); document.StyleSheets.AddChild(styleSheet); // Create a map importer m_MapImporter = new NEsriMapImporter(); m_MapImporter.MapBounds = NMapBounds.World; // Add a shapefile NEsriShapefile countries = new NEsriShapefile(Path.Combine(Application.StartupPath, Countries)); countries.NameColumn = "CNTRY_NAME"; countries.TextColumn = "CNTRY_NAME"; m_MapImporter.AddLayer(countries); // Read the map data m_MapImporter.Read(); // Create a fill rule NMapFillRuleRange fillRule = new NMapFillRuleRange("POP_CNTRY", Color.White, Color.Black, 12); fillRule.DataGrouping = m_DataGrouping; countries.FillRule = fillRule; // Associate a shape created listener and import the map data m_MapImporter.ShapeCreatedListener = new NCustomShapeCreatedListener(); m_MapImporter.Import(document, document.Bounds); // Generate a legend NMapLegendRange mapLegend = (NMapLegendRange)m_MapImporter.GetLegend(fillRule); mapLegend.Title = "Population"; mapLegend.RangeFormatString = "{0:N0} - {1:N0} people"; mapLegend.LastFormatString = "{0:N0} people and more"; if (pMapLegend == null) { pMapLegend = new Panel(); pMapLegend.Location = new Point(btnRecreateMap.Left, btnRecreateMap.Bottom + 10); pMapLegend.Width = btnRecreateMap.Width; pMapLegend.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; this.Controls.Add(pMapLegend); } mapLegend.Create(pMapLegend); }