Example #1
0
 private void fileLayoutToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (Shape s in display1.Diagram.Shapes) {
         s.X = 100;
         s.Y = 100;
     }
     RepulsionLayouter layouter = new RepulsionLayouter(project1);
     layouter.SpringRate = 8;
     layouter.Repulsion = 3;
     layouter.RepulsionRange = 500;
     layouter.Friction = 0;
     layouter.Mass = 50;
     layouter.AllShapes = display1.Diagram.Shapes;
     layouter.Shapes = display1.Diagram.Shapes;
     //
     layouter.Prepare();
     layouter.Execute(10);
     layouter.Fit(50, 50, display1.Diagram.Width - 100, display1.Diagram.Height - 100);
 }
        public void PerformTableLayouting(List<TableModel> tableContainer)
        {
            RepulsionLayouter layouter = new RepulsionLayouter(Project)
            {
                SpringRate = 10,
                Repulsion = 40,
                RepulsionRange = 510,
                Friction = 0,
                Mass = 1200,
                AllShapes = TableDiagram.Shapes,
                Shapes = TableDiagram.Shapes
            };

            layouter.Prepare();
            layouter.Execute(10);
            layouter.Fit(50, 50, TableDiagram.Width - 100, TableDiagram.Height - 100);

            foreach (var tabModel in tableContainer)
            {
                var shape = TableDiagram.Shapes.Single(t => t.Tag.ToString() == tabModel.Name);
                tabModel.ShapePlacementInfo.Location = new Point(shape.X, shape.Y);
            }
        }
Example #3
0
		private void loadWebStatisticsToolStripMenuItem_Click(object sender, EventArgs e) {
			string statsDir = Path.Combine("Demo Programs", Path.Combine("WebVisits", "Sample Web Statistics"));
			openFileDialog.Filter = "Web Statistics|*.xml|All files|*.*";
			openFileDialog.InitialDirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)), statsDir);
			openFileDialog.FileName = string.Empty;
			if (openFileDialog.ShowDialog() == DialogResult.OK) {
				// Create a new diagram
				ShapeType boxType = project.ShapeTypes["Ellipse"];
				ShapeType multiLineType = project.ShapeTypes["Polyline"];
				
				Dictionary<int, RectangleBase> boxes = new Dictionary<int, RectangleBase>();
				List<Polyline> lines = new List<Polyline>();
				//
				// Create shapes for the web pages and connect them with lines
				XmlScanner scanner = new XmlScanner(openFileDialog.FileName);
				scanner.ReadElement();
				scanner.ReadElement("WebVisits");
				scanner.ReadChild("Pages");
				if (scanner.ReadChild("Page")) do {
					scanner.ReadAttribute(); // id attribute
					RectangleBase box = (RectangleBase)boxType.CreateInstance(pageTemplate);
					box.Width = 140;
					boxes.Add(scanner.IntValue, box);
					scanner.ReadAttribute();
					box.Text = scanner.StringValue;
				} while (scanner.ReadElement());
				scanner.ReadParent();
				if (scanner.ReadChild("Referral"))
					do {
						scanner.ReadAttribute(); // id1
						int id1 = scanner.IntValue;
						Shape shape1 = boxes[id1];
						scanner.ReadAttribute(); // id2
						int id2 = scanner.IntValue;
						Shape shape2 = boxes[id2];
						scanner.ReadAttribute(); // count
						int count = scanner.IntValue;
						Polyline line = (Polyline)multiLineType.CreateInstance();
						line.EndCapStyle = project.Design.CapStyles.Arrow;
						line.LineStyle = GetLineStyle(count);
						line.Connect(ControlPointId.FirstVertex, shape1, ControlPointId.Reference);
						line.Connect(ControlPointId.LastVertex, shape2, ControlPointId.Reference);
						lines.Add(line);
					} while (scanner.ReadElement());
				scanner.ReadParent();
				scanner.Close();
				//
				// Insert all shapes into the diagram
				int cnt = 0;
				foreach (Diagram d in project.Repository.GetDiagrams())
					++cnt;
				Diagram diagram = new Diagram(string.Format("WebVisits Diagram {0}", cnt));
				diagram.Width = 1000;
				diagram.Height = 1000;
				diagram.BackgroundImageLayout = Dataweb.NShape.ImageLayoutMode.Fit;
				foreach (RectangleBase b in boxes.Values)
					diagram.Shapes.Add(b, project.Repository.ObtainNewTopZOrder(diagram));
				foreach (Polyline l in lines)
					diagram.Shapes.Add(l, project.Repository.ObtainNewBottomZOrder(diagram));
				
				boxes.Clear();
				lines.Clear();
				//
				// Insert the diagram (including all shapes) into the repository
				project.Repository.InsertDiagram(diagram);
				//
				// Layout the shapes
				if (layouter == null)
					layouter = new RepulsionLayouter(project);
				layouter.SpringRate = 14;
				layouter.Repulsion = 7;
				layouter.RepulsionRange = 400;
				layouter.Friction = 0;
				layouter.Mass = 50;
				//
				layouter.AllShapes = diagram.Shapes;
				layouter.Shapes = diagram.Shapes;

				layouter.Prepare();
				layouter.Execute(10);
				layouter.Fit(50, 50, diagram.Width- 100, diagram.Height-100);
				//
				// Display the result
				display.Diagram = diagram;
			}
		}
Example #4
0
		private void PrepareLayouter()
		{
			switch ((string) currentPanel.Tag) {
				case "Expansion": // Distribution
					if (layouter == null || !(layouter is ExpansionLayouter))
						layouter = new ExpansionLayouter(Project);
					ExpansionLayouter dl = (ExpansionLayouter) layouter;
					dl.HorizontalCompression = horizontalCompressionTrackBar.Value;
					dl.VerticalCompression = verticalCompressionTrackBar.Value;
					break;
				case "Alignment":
					if (layouter == null || !(layouter is GridLayouter))
						layouter = new GridLayouter(Project);
					GridLayouter gl = (GridLayouter) layouter;
					gl.CoarsenessX = columnDistanceTrackBar.Value;
					gl.CoarsenessY = rowDistanceTrackBar.Value;
					/* gl.ColumnDistance = columnDistanceTrackBar.Value;
					gl.RowDistance = rowDistanceTrackBar.Value; */
					break;
				case "Clusters":
					if (layouter == null || !(layouter is RepulsionLayouter))
						layouter = new RepulsionLayouter(Project);
					RepulsionLayouter rl = (RepulsionLayouter) layouter;
					// The default distance between connected elements should be 100 display units.
					// The default distance between unconnected elements should be 300 display units.
					rl.Friction = 0; // 300;
					rl.Repulsion = repulsionStrengthTrackBar.Value;
					rl.RepulsionRange = repulsionRangeTrackBar.Value;
					rl.SpringRate = attractionStrengthTrackBar.Value;
					// Two unconnected elements at the same position should move to their default distance 
					// within two steps
					rl.Mass = 50;
					break;
				case "Flow":
					if (layouter == null || !(layouter is FlowLayouter))
						layouter = new FlowLayouter(Project);
					FlowLayouter fl = (FlowLayouter) layouter;
					if (bottomUpRadioButton.Checked) fl.Direction = FlowLayouter.FlowDirection.BottomUp;
					else if (leftToRightRadioButton.Checked) fl.Direction = FlowLayouter.FlowDirection.LeftToRight;
					else if (topDownRadioButton.Checked) fl.Direction = FlowLayouter.FlowDirection.TopDown;
					else if (rightToLeftRadioButton.Checked) fl.Direction = FlowLayouter.FlowDirection.RightToLeft;
					fl.LayerDistance = flowLayerDistanceTrackBar.Value;
					fl.RowDistance = flowRowDistanceTrackBar.Value;
					break;
				default:
					Debug.Assert(false);
					break;
			}
		}