Пример #1
0
        public OrganizationalChart()
        {
            selectionPicker1 = new UIPickerView();
            this.OptionView  = new UIView();

            string deviceType = UIDevice.CurrentDevice.Model;

            overviewLabel                  = new UILabel();
            overviewLabel.Text             = "Enable Overview";
            overviewLabel.TextColor        = UIColor.Black;
            overviewLabel.TextAlignment    = UITextAlignment.Left;
            overviewLabel.BackgroundColor  = UIColor.Clear;
            overviewLabel.Frame            = new CGRect(this.Frame.X + 10, 70, 150, 30);
            overviewSwitch                 = new UISwitch();
            overviewSwitch.On              = true;
            overviewSwitch.Frame           = new CGRect(this.Frame.X + 250, 70, 50, 30);
            overviewSwitch.TouchUpInside  += OverviewSwitch_TouchUpInside;
            overviewSwitch.BackgroundColor = UIColor.Clear;

            dragLabel                  = new UILabel();
            dragLabel.Text             = "Change Hierarchy";
            dragLabel.TextColor        = UIColor.Black;
            dragLabel.TextAlignment    = UITextAlignment.Left;
            dragLabel.BackgroundColor  = UIColor.Clear;
            dragLabel.Frame            = new CGRect(this.Frame.X + 10, 10, 150, 30);
            dragSwitch                 = new UISwitch();
            dragSwitch.On              = false;
            dragSwitch.Frame           = new CGRect(this.Frame.X + 250, 10, 50, 30);
            dragSwitch.TouchUpInside  += dragSwitch_TouchUpInside;
            dragSwitch.BackgroundColor = UIColor.Clear;

            diagram = new SfDiagram();
            //Dictionary collection
            FillColor = new Dictionary <string, UIColor>();
            FillColor.Add("Managing Director", UIColor.FromRGB(239, 75, 93));
            FillColor.Add("Project Manager", UIColor.FromRGB(49, 162, 255));
            FillColor.Add("Senior Manager", UIColor.FromRGB(49, 162, 255));
            FillColor.Add("Project Lead", UIColor.FromRGB(0, 194, 192));
            FillColor.Add("Senior S/W Engg", UIColor.FromRGB(0, 194, 192));
            FillColor.Add("Software Engg", UIColor.FromRGB(0, 194, 192));
            FillColor.Add("Team Lead", UIColor.FromRGB(0, 194, 192));
            FillColor.Add("Project Trainee", UIColor.FromRGB(255, 129, 0));

            StrokeColor = new Dictionary <string, CGColor>();
            StrokeColor.Add("Managing Director", UIColor.FromRGB(201, 32, 61).CGColor);
            StrokeColor.Add("Project Manager", UIColor.FromRGB(23, 132, 206).CGColor);
            StrokeColor.Add("Senior Manager", UIColor.FromRGB(23, 132, 206).CGColor);
            StrokeColor.Add("Project Lead", UIColor.FromRGB(4, 142, 135).CGColor);
            StrokeColor.Add("Senior S/W Engg", UIColor.FromRGB(4, 142, 135).CGColor);
            StrokeColor.Add("Software Engg", UIColor.FromRGB(4, 142, 135).CGColor);
            StrokeColor.Add("Team Lead", UIColor.FromRGB(4, 142, 135).CGColor);
            StrokeColor.Add("Project Trainee", UIColor.FromRGB(206, 98, 9).CGColor);

            diagram.BeginNodeRender   += Dia_BeginNodeRender;
            diagram.ItemLongPressed   += Dia_ItemLongPressed;
            diagram.LayoutNodeDropped += Diagram_OnLayoutNodeDropped;
            diagram.BackgroundColor    = UIColor.White;
            diagram.EnableSelectors    = false;
            diagram.NodeClicked       += Dia_NodeClicked;
            diagram.Loaded            += Dia_Loaded;
            //Initialize Method
            datamodel = new DataModel();
            datamodel.Data();

            //To Represent DataSourceSttings Properties
            DataSourceSettings settings = new DataSourceSettings();

            settings.ParentId          = "ReportingPerson";
            settings.Id                = "Name";
            settings.DataSource        = datamodel.employee;
            diagram.DataSourceSettings = settings;

            //To Represent LayoutManager Properties
            diagram.LayoutManager = new LayoutManager()
            {
                Layout = new DirectedTreeLayout()
                {
                    Type = LayoutType.Organization,
                    HorizontalSpacing = 35,
                }
            };

            for (int i = 0; i < diagram.Connectors.Count; i++)
            {
                diagram.Connectors[i].TargetDecoratorType = DecoratorType.None;
                diagram.Connectors[i].Style.StrokeBrush   = new SolidBrush(UIColor.FromRGB(127, 132, 133));
                diagram.Connectors[i].Style.StrokeWidth   = 1;
            }
            this.AddSubview(diagram);
            diagram.Width  = (float)this.Frame.Width;
            diagram.Height = (float)this.Frame.Height;
            OptionView.AddSubview(dragLabel);
            OptionView.AddSubview(dragSwitch);

            if (deviceType == "iPad")
            {
                OptionView.AddSubview(overviewLabel);
                OptionView.AddSubview(overviewSwitch);
                overviewPanel = new OverviewPanel();
                overviewPanel.Layer.BorderColor = UIColor.Orange.CGColor;
                overviewPanel.Layer.BorderWidth = 2;
                overviewPanel.Frame             = new CGRect(0,
                                                             0,
                                                             UIScreen.MainScreen.Bounds.Width / 2,
                                                             UIScreen.MainScreen.Bounds.Height / 4);
                diagram.AddSubview(overviewPanel);
                diagram.OverviewPanel = overviewPanel;
            }
        }