Profile Picture

Change object color and shape via data import

Posted By Tom Walls 15 Years Ago
Author
Message
Tom Walls
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 2, Visits: 1
Excellent thank you!!

Ivo Milanov
Posted 15 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15
Hi Tom,

The following source code makes a simple drawing which imports data from two tables. The vertices have different shape and color, and edges have labels:

using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

using Nevron.Diagram;
using Nevron.Diagram.DataImport;
using Nevron.Diagram.Layout;
using Nevron.Diagram.WinForm;
using Nevron.GraphicsCore;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
NDrawingView view = new NDrawingView();
Controls.Add(view);
view.Dock = DockStyle.Fill;

NDrawingDocument doc = new NDrawingDocument();
view.Document = doc;

DataTable vtable = new DataTable();
vtable.Columns.Add("id", typeof(int));
vtable.Columns.Add("text", typeof(string));

vtable.Rows.Add(1, "root");
vtable.Rows.Add(2, "c1");
vtable.Rows.Add(3, "c2");

DataTable etable = new DataTable();
etable.Columns.Add("from", typeof(int));
etable.Columns.Add("to", typeof(int));
etable.Columns.Add("text", typeof(string));

etable.Rows.Add(1, 2, "label1");
etable.Rows.Add(1, 3, "label2");

NGraphDataSourceImporter importer = new NGraphDataSourceImporter();
importer.Document = doc;
importer.VertexDataSource = vtable;
importer.EdgeDataSource = etable;
importer.VertexIdColumnName = "id";
importer.FromVertexIdColumnName = "from";
importer.ToVertexIdColumnName = "to";
importer.Layout = new NLayeredGraphLayout();
importer.VertexShapesFactory = new MyShapeFactory();
importer.VertexImported += new ShapeImportedDelegate(importer_VertexImported);
importer.EdgeImported += new ShapeImportedDelegate(importer_EdgeImported);
importer.Import();
}
void importer_EdgeImported(NDataSourceImporter dataSourceImporter, NShape shape, INDataRecord record)
{
shape.Text = record.GetColumnValue("text").ToString();
}
void importer_VertexImported(NDataSourceImporter dataSourceImporter, NShape shape, INDataRecord record)
{
shape.Text = record.GetColumnValue("text").ToString();

NCompositeShape cshape = shape as NCompositeShape;
if (shape.Text == "root")
{
cshape.Primitives.AddChild(new NRectanglePath(0, 0, 100, 100));
cshape.Style.FillStyle = new NColorFillStyle(Color.Blue);
}
else
{
cshape.Primitives.AddChild(new NEllipsePath(0, 0, 100, 100));
cshape.Style.FillStyle = new NColorFillStyle(Color.Red);
}

cshape.UpdateModelBounds();
cshape.CreateShapeElements(ShapeElementsMask.Ports);
cshape.Ports.AddChild(new NDynamicPort(new NContentAlignment(), DynamicPortGlueMode.GlueToContour));
}
public class MyShapeFactory : INShapesFactory
{
#region INShapesFactory Members

public bool CanCreateShape(string name)
{
return true;
}

public NShape CreateShape(string name)
{
return new NCompositeShape();
}

#endregion
}
}
}

We have implemented a simple shape factory, which always returns a composite shape. In the VertexImported handler the composite shape geometry primitives are initialized depending on the data record for which the vertex is created.

By default if an edge factory is not assigned the data importer will create NRoutableConnector instances. These connectors have a single label of type NLogicalLineLabel which is anchored to 50% of the connector legnth. Setting the Text property of the connector will actually set this label text value.

Hope this helps - questions or comments - please feel free...

Best regards,
Ivo

Tom Walls
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 2, Visits: 1
Hi we are evaluating your product (verge of buying) for a web diagramming image which is a part of a system we are building for one of our clients.

We are close in that we are trying to use the DataImport for a graph using data tables (views). We are pretty close but our problem is that the requirement we have from the client requires us to add labels to the connectors (sometimes) and change certain objects from ellipse to process squares and change from one color to another (red) as a visual queue. We haven't figured out how to do that with the standard data import you have if its possible.

I have added two graphic images of a examples that are pretty normal that we have to create from stored information in our database. Any examples would be HUGE!!

Thanks
Tom Walls


Ok I got this working on the color now need help with shape itself:


if ( shape.Text.Contains("Online"))
shape.Style.FillStyle = new NColorFillStyle(Color.Red);



Similar Topics


Reading This Topic