//To change the Spacing properties /// <summary> /// HorizontalSpacing ,VerticalSpacing and SpaceBetweenSubTrees /// Description: /// Provide the spaces between the edges of the adjacent nodes (Siblings)[HorizontalSpacing]. /// Provide spaces between the nodes that lie at the next levels of the layout[VerticalSpacing]. /// Provide the sthe spaces between adjacent Subtrees[SpaceBetweenSubTrees]. /// Property of DiagramModel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { TextBox box = (sender as TextBox); DirectedTreeLayout dtlayout = new DirectedTreeLayout(diagramModel, diagramView); if (diagramModel != null) { if (box.Text != string.Empty) { switch (box.Name) { case "Hspace": diagramModel.HorizontalSpacing = double.Parse(box.Text); dtlayout.RefreshLayout(); break; case "Vspace": diagramModel.VerticalSpacing = double.Parse(box.Text); dtlayout.RefreshLayout(); break; case "Sspace": diagramModel.SpaceBetweenSubTrees = double.Parse(box.Text); dtlayout.RefreshLayout(); break; } } } }
//Refresh the Layout private void refershLayout(TreeOrientation treeorientation) { DirectedTreeLayout tree = new DirectedTreeLayout(diagramModel, diagramView); diagramModel.Orientation = treeorientation; tree.RefreshLayout(); }
//Refreshing the Layout private void refershLayout(TreeOrientation treeorientation) { DirectedTreeLayout tree = new DirectedTreeLayout(diagramModel, diagramView); diagramModel.Orientation = treeorientation; tree.RefreshLayout(); (diagramView.Page as DiagramPage).InvalidateMeasure(); (diagramView.Page as DiagramPage).InvalidateArrange(); }
private void CreateView(ContextViewMode mode, DiagramControl source, DiagramControl target) { ContextViewManager ContextView = new ContextViewManager(source, target); ContextView.ContextViewMode = mode; DirectedTreeLayout layout = new DirectedTreeLayout(diagramModel, diagramView); diagramModel.HorizontalSpacing = 10; diagramModel.VerticalSpacing = 80; diagramModel.SpaceBetweenSubTrees = 10; ContextView.Layout = layout; }
public MainWindow() { this.InitializeComponent(); //Initialize Nodes and Connectors this.sfdiagram.Nodes = new DiagramCollection <NodeViewModel>(); this.sfdiagram.Connectors = new DiagramCollection <CustomConnectorViewModel>(); this.sfdiagram.HorizontalRuler = new Ruler { Orientation = Orientation.Horizontal }; this.sfdiagram.VerticalRuler = new Ruler { Orientation = Orientation.Vertical }; layoutSettings = new DirectedTreeLayout { Type = LayoutType.Hierarchical, Orientation = TreeOrientation.TopToBottom, HorizontalSpacing = 40, VerticalSpacing = 40, Margin = new Thickness(), AvoidSegmentOverlapping = true, }; //To Represent LayoutManager Properties this.sfdiagram.LayoutManager = new LayoutManager { Layout = layoutSettings }; //PageSettings used to enable the Appearance of Digram Page. this.sfdiagram.PageSettings.PageBorderBrush = new SolidColorBrush(Colors.Transparent); var data = new ObservableCollection <ItemInfo>(); //Initialize Method this.GetDataSource(data); //Initialize DataSourceSettings and Represent ParentId,Id. var settings = new DataSourceSettings(); settings.ParentId = "ReportingPerson"; settings.Id = "Name"; settings.DataSource = data; this.sfdiagram.DataSourceSettings = settings; this.Loaded += MainWindow_Loaded; this.sfdiagram.Tool = Tool.ZoomPan; }
public Connectors() { HeaderBar.BackgroundColor = UIColor.FromRGB(245, 245, 245); var label = new UILabel(); label.Text = "Connector Types: "; label.TextColor = UIColor.Black; label.BackgroundColor = UIColor.Clear; label.TextAlignment = UITextAlignment.Center; string deviceType = UIDevice.CurrentDevice.Model; int offsetX; int space; if (deviceType == "iPhone" || deviceType == "iPod touch") { offsetX = 150; space = 10; } else { offsetX = 180; space = 40; } label.Frame = new CGRect(0, 0, offsetX, 60); HeaderBar.AddSubview(label); offsetX += space; straight = AddButton(offsetX, "Images/Diagram/CSStraight.png"); straight.TouchUpInside += Straight_TouchUpInside; HeaderBar.AddSubview(straight); offsetX += space + 40; curve = AddButton(offsetX, "Images/Diagram/CSCurve.png"); curve.TouchUpInside += Curve_TouchUpInside;; HeaderBar.AddSubview(curve); offsetX += space + 40; ortho = AddButton(offsetX, "Images/Diagram/CSOrtho.png"); ortho.TouchUpInside += Ortho_TouchUpInside; ortho.BackgroundColor = UIColor.FromRGB(30, 144, 255); HeaderBar.AddSubview(ortho); selectionPicker1 = new UIPickerView(); this.OptionView = new UIView(); PickerModel model = new PickerModel(verticalOrientationlist); selectionPicker1.Model = model; connectorStyle = new UILabel(); connectorStyle.Text = "Connector Style"; connectorStyle.TextColor = UIColor.Black; connectorStyle.TextAlignment = UITextAlignment.Left; connectorSize = new UILabel(); connectorSize.Text = "Connector Size"; connectorSize.TextColor = UIColor.Black; connectorSize.TextAlignment = UITextAlignment.Left; //Represent the vertical button connectorStyleButton = new UIButton(); connectorStyleButton.SetTitle("Default", UIControlState.Normal); connectorStyleButton.SetTitleColor(UIColor.Black, UIControlState.Normal); connectorStyleButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; connectorStyleButton.Layer.CornerRadius = 8; connectorStyleButton.Layer.BorderWidth = 2; connectorStyleButton.TouchUpInside += ShowPicker1; connectorStyleButton.BackgroundColor = UIColor.LightGray; connectorStyleButton.Layer.BorderColor = UIColor.FromRGB(246, 246, 246).CGColor; plus = new UIButton(); plus.BackgroundColor = UIColor.White; plus.Layer.CornerRadius = 8; plus.Layer.BorderWidth = 0.5f; plus.TouchUpInside += Plus_TouchUpInside; plusimg = new UIImageView(); plusimg.Image = UIImage.FromBundle("Images/Diagram/CSplus.png"); plus.AddSubview(plusimg); minus = new UIButton(); minus.BackgroundColor = UIColor.White; minus.Layer.CornerRadius = 8; minus.Layer.BorderWidth = 0.5f; minus.TouchUpInside += Minus_TouchUpInside; minusimg = new UIImageView(); minusimg.Image = UIImage.FromBundle("Images/Diagram/CSsub.png"); minus.AddSubview(minusimg); sizeindicator = new UILabel(); sizeindicator.Text = width.ToString(); sizeindicator.BackgroundColor = UIColor.Clear; sizeindicator.TextColor = UIColor.Black; sizeindicator.TextAlignment = UITextAlignment.Center; //Represent the button doneButton.SetTitle("Done\t", UIControlState.Normal); doneButton.SetTitleColor(UIColor.Black, UIControlState.Normal); doneButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right; doneButton.TouchUpInside += HidePicker; doneButton.Hidden = true; doneButton.BackgroundColor = UIColor.FromRGB(246, 246, 246); selectionPicker1.ShowSelectionIndicator = true; selectionPicker1.Hidden = true; ObservableCollection <EmployeeDetail> employees = new ObservableCollection <EmployeeDetail>(); employees.Add(new EmployeeDetail() { Name = "Elizabeth", EmpId = "1", ParentId = "", Designation = "CEO" }); employees.Add(new EmployeeDetail() { Name = "Christina", EmpId = "2", ParentId = "1", Designation = "Manager" }); employees.Add(new EmployeeDetail() { Name = "Yang", EmpId = "3", ParentId = "1", Designation = "Manager" }); employees.Add(new EmployeeDetail() { Name = "Yoshi", EmpId = "4", ParentId = "2", Designation = "Team Lead" }); employees.Add(new EmployeeDetail() { Name = "Yoshi", EmpId = "5", ParentId = "2", Designation = "Co-ordinator" }); employees.Add(new EmployeeDetail() { Name = "Philip", EmpId = "6", ParentId = "4", Designation = "Developer" }); employees.Add(new EmployeeDetail() { Name = "Philip", EmpId = "7", ParentId = "4", Designation = "Testing Engineer" }); employees.Add(new EmployeeDetail() { Name = "Roland", EmpId = "8", ParentId = "3", Designation = "Team Lead" }); employees.Add(new EmployeeDetail() { Name = "Yoshi", EmpId = "9", ParentId = "3", Designation = "Co-ordinator" }); employees.Add(new EmployeeDetail() { Name = "Yuonne", EmpId = "10", ParentId = "8", Designation = "Developer" }); employees.Add(new EmployeeDetail() { Name = "Philip", EmpId = "10", ParentId = "8", Designation = "Testing Engineer" }); //Initializes the DataSourceSettings diagram.DataSourceSettings = new DataSourceSettings() { DataSource = employees, Id = "EmpId", ParentId = "ParentId" }; //Initializes the Layout DirectedTreeLayout treelayout = new DirectedTreeLayout() { HorizontalSpacing = 80, VerticalSpacing = 50, TreeOrientation = TreeOrientation.TopToBottom }; diagram.LayoutManager = new LayoutManager() { Layout = treelayout }; diagram.IsReadOnly = true; diagram.BeginNodeRender += Diagram_BeginNodeRender; diagram.Loaded += Diagram_Loaded; HeaderBar.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 60); diagramView.Frame = new CGRect(0, 70, UIScreen.MainScreen.Bounds.Width + 40, UIScreen.MainScreen.Bounds.Height - HeaderBar.Frame.Height); diagramView.BackgroundColor = UIColor.Clear; diagram.Layer.BorderColor = UIColor.Clear.CGColor; diagram.Layer.BorderWidth = 0; diagramView.AddSubview(diagram); diagramView.MarginTop = HeaderBar.Frame.Height; this.AddSubview(diagramView); this.AddSubview(HeaderBar); model.PickerChanged += SelectedIndexChanged; for (int i = 0; i < diagram.Connectors.Count; i++) { diagram.Connectors[i].TargetDecoratorType = DecoratorType.None; } foreach (var view in this.Subviews) { connectorStyle.Frame = new CGRect(this.Frame.X + 10, 0, PopoverSize.Width - 20, 30); connectorStyleButton.Frame = new CGRect(this.Frame.X + 10, 40, PopoverSize.Width - 20, 30); connectorSize.Frame = new CGRect(this.Frame.X + 10, 80, PopoverSize.Width - 20, 30); plus.Frame = new CGRect(this.Frame.X + 60, 120, 30, 30); plusimg.Frame = new CGRect(0, 0, 30, 30); minus.Frame = new CGRect(this.Frame.X + 160, 120, 30, 30); minusimg.Frame = new CGRect(0, 0, 30, 30); sizeindicator.Frame = new CGRect(this.Frame.X + 110, 120, 30, 30); selectionPicker1.Frame = new CGRect(0, PopoverSize.Height / 2, PopoverSize.Width, PopoverSize.Height / 3); doneButton.Frame = new CGRect(0, PopoverSize.Height / 2.5, PopoverSize.Width, 40); } optionView(); diagram.ContextMenuSettings.Visibility = false; }
public Connectors() { InitializeComponent(); diagram.ContextMenuSettings.Visibility = false; diagram.IsReadOnly = true; if (Device.RuntimePlatform == Device.Android) { Xamarin.Forms.DependencyService.Get <IText>().GenerateFactor(); } if (Device.RuntimePlatform == Device.UWP) { diagram.PageSettings.PageWidth = 1600; diagram.BackgroundColor = Color.White; } ObservableCollection <Employee> employees = new ObservableCollection <Employee>(); employees.Add(new Employee() { Name = "Elizabeth", EmpId = "1", ParentId = "", Designation = "CEO" }); employees.Add(new Employee() { Name = "Christina", EmpId = "2", ParentId = "1", Designation = "Manager" }); employees.Add(new Employee() { Name = "Yang", EmpId = "3", ParentId = "1", Designation = "Manager" }); employees.Add(new Employee() { Name = "Yoshi", EmpId = "4", ParentId = "2", Designation = "Team Lead" }); employees.Add(new Employee() { Name = "Yoshi", EmpId = "5", ParentId = "2", Designation = "Co-ordinator" }); employees.Add(new Employee() { Name = "Philip", EmpId = "6", ParentId = "4", Designation = "Developer" }); employees.Add(new Employee() { Name = "Philip", EmpId = "7", ParentId = "4", Designation = "Testing Engineer" }); employees.Add(new Employee() { Name = "Roland", EmpId = "8", ParentId = "3", Designation = "Team Lead" }); employees.Add(new Employee() { Name = "Yoshi", EmpId = "9", ParentId = "3", Designation = "Co-ordinator" }); employees.Add(new Employee() { Name = "Yuonne", EmpId = "10", ParentId = "8", Designation = "Developer" }); employees.Add(new Employee() { Name = "Philip", EmpId = "10", ParentId = "8", Designation = "Testing Engineer" }); //Initializes the DataSourceSettings diagram.DataSourceSettings = new DataSourceSettings() { DataSource = employees, Id = "EmpId", ParentId = "ParentId" }; //Initializes the Layout DirectedTreeLayout treelayout = new DirectedTreeLayout() { HorizontalSpacing = 80, VerticalSpacing = 50 * DiagramUtility.currentDensity, TreeOrientation = TreeOrientation.TopToBottom }; diagram.LayoutManager = new LayoutManager() { Layout = treelayout }; for (int i = 0; i < diagram.Connectors.Count; i++) { diagram.Connectors[i].TargetDecoratorType = DecoratorType.None; diagram.Connectors[i].Style.StrokeWidth = 1 * DiagramUtility.currentDensity; } diagram.BeginNodeRender += Diagram_BeginNodeRender; diagram.Loaded += Diagram_Loaded; strokeStyle.Items.Add("Default"); strokeStyle.Items.Add("Dashed"); strokeStyle.Items.Add("Dotted"); strokeStyle.SelectedIndex = 0; strokeStyle.SelectedIndexChanged += StrokeStyle_SelectedIndexChanged; }
public override View GetSampleContent(Context context) { m_context = context; currentDensity = m_context.Resources.DisplayMetrics.Density; //Initialize the SfDiagram and set its background color. diagram = new SfDiagram(context); diagram.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); diagram.IsReadOnly = true; ObservableCollection <Employee> employees = new ObservableCollection <Employee>(); employees.Add(new Employee() { Name = "Elizabeth", EmpId = "1", ParentId = "", Designation = "CEO" }); employees.Add(new Employee() { Name = "Christina", EmpId = "2", ParentId = "1", Designation = "Manager" }); employees.Add(new Employee() { Name = "Yang", EmpId = "3", ParentId = "1", Designation = "Manager" }); employees.Add(new Employee() { Name = "Yoshi", EmpId = "4", ParentId = "2", Designation = "Team Lead" }); employees.Add(new Employee() { Name = "Yoshi", EmpId = "5", ParentId = "2", Designation = "Co-ordinator" }); employees.Add(new Employee() { Name = "Philip", EmpId = "6", ParentId = "4", Designation = "Developer" }); employees.Add(new Employee() { Name = "Philip", EmpId = "7", ParentId = "4", Designation = "Testing Engineer" }); employees.Add(new Employee() { Name = "Roland", EmpId = "8", ParentId = "3", Designation = "Team Lead" }); employees.Add(new Employee() { Name = "Yoshi", EmpId = "9", ParentId = "3", Designation = "Co-ordinator" }); employees.Add(new Employee() { Name = "Yuonne", EmpId = "10", ParentId = "8", Designation = "Developer" }); employees.Add(new Employee() { Name = "Philip", EmpId = "10", ParentId = "8", Designation = "Testing Engineer" }); //Initializes the DataSourceSettings diagram.DataSourceSettings = new DataSourceSettings() { DataSource = employees, Id = "EmpId", ParentId = "ParentId" }; //Initializes the Layout DirectedTreeLayout treelayout = new DirectedTreeLayout() { HorizontalSpacing = 80, VerticalSpacing = 50 * currentDensity, TreeOrientation = TreeOrientation.TopToBottom }; diagram.LayoutManager = new LayoutManager() { Layout = treelayout }; diagram.BeginNodeRender += Diagram_BeginNodeRender; diagram.Loaded += Diagram_Loaded; LinearLayout linearLayout = new LinearLayout(context) { Orientation = Android.Widget.Orientation.Vertical }; LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); layoutParams.TopMargin = 25 * (int)MainActivity.factor; linearLayout.LayoutParameters = layoutParams; LinearLayout typesBar = new LinearLayout(context); typesBar.SetBackgroundColor(Color.Rgb(245, 245, 245)); layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); typesBar.SetMinimumHeight(200 * (int)MainActivity.factor); typesBar.SetPadding(0, 10 * (int)MainActivity.factor, 0, 10 * (int)MainActivity.factor); TextView selectText = new TextView(context) { LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent), Text = "Connector Types:", TextAlignment = TextAlignment.Gravity, Gravity = GravityFlags.Center | GravityFlags.CenterVertical, TextSize = 15 * MainActivity.factor }; int width = (int)(context.Resources.DisplayMetrics.WidthPixels - context.Resources.DisplayMetrics.Density); selectText.SetMinimumWidth((int)(width * 0.4 * MainActivity.factor)); ImageButtonView straightButton = new ImageButtonView(context); straightButton.Click += ButtonTouch; straightButton.ImageId = "DiagramStraight"; straightButton.LayoutParameters = new ViewGroup.LayoutParams(180 * (int)MainActivity.factor, 180 * (int)MainActivity.factor); ImageView straightImage = new ImageView(context); var imageId = straightButton.ImageId + ".png"; if (imageId != null) { var imageData = LoadResource(imageId).ToArray(); straightImage.SetImageBitmap(BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length)); } straightImage.Layout((int)(40 * MainActivity.factor), (int)(40 * MainActivity.factor), (int)(110 * MainActivity.factor), (int)(110 * MainActivity.factor)); straightButton.AddView(straightImage); ImageButtonView curveButton = new ImageButtonView(context); curveButton.Click += ButtonTouch; curveButton.ImageId = "DiagramCurve"; curveButton.LayoutParameters = new ViewGroup.LayoutParams(180 * (int)MainActivity.factor, 180 * (int)MainActivity.factor); ImageView curveImage = new ImageView(context); imageId = curveButton.ImageId + ".png"; if (imageId != null) { var imageData = LoadResource(imageId).ToArray(); curveImage.SetImageBitmap(BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length)); } curveImage.Layout((int)(40 * MainActivity.factor), (int)(40 * MainActivity.factor), (int)(110 * MainActivity.factor), (int)(110 * MainActivity.factor)); curveButton.AddView(curveImage); ImageButtonView edgeButton = new ImageButtonView(context); edgeButton.Click += ButtonTouch; edgeButton.LayoutParameters = new ViewGroup.LayoutParams(180 * (int)MainActivity.factor, 180 * (int)MainActivity.factor); edgeButton.ImageId = "DiagramEdge"; ImageView edgeImage = new ImageView(context); imageId = edgeButton.ImageId + ".png"; if (imageId != null) { var imageData = LoadResource(imageId).ToArray(); edgeImage.SetImageBitmap(BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length)); } edgeImage.Layout((int)(40 * MainActivity.factor), (int)(40 * MainActivity.factor), (int)(110 * MainActivity.factor), (int)(110 * MainActivity.factor)); edgeButton.AddView(edgeImage); buttons = new LinearLayout(context); buttons.SetMinimumWidth((int)(width - width * 0.4 * MainActivity.factor)); buttons.SetBackgroundColor(Color.Transparent); buttons.AddView(straightButton); TextView view = new TextView(context); view.SetWidth(30 * (int)MainActivity.factor); view.SetBackgroundColor(Color.Transparent); buttons.AddView(view); buttons.AddView(curveButton); view = new TextView(context); view.SetWidth(30 * (int)MainActivity.factor); view.SetBackgroundColor(Color.Transparent); buttons.AddView(view); buttons.AddView(edgeButton); typesBar.AddView(selectText); typesBar.AddView(buttons); linearLayout.AddView(typesBar); linearLayout.AddView(diagram); for (int i = 0; i < diagram.Connectors.Count; i++) { diagram.Connectors[i].TargetDecoratorType = DecoratorType.None; diagram.Connectors[i].Style.StrokeWidth = 1; } return(linearLayout); }