public void TestLayout() { var dataSource = new TestDataSource(); new TestDataGen().GenerateDataItems(dataSource, 10, 0); var boxContainer = new BoxContainer(dataSource); TestDataGen.GenerateBoxSizes(boxContainer); var diagram = new Diagram(); diagram.Boxes = boxContainer; diagram.LayoutSettings.LayoutStrategies.Add("default", new LinearLayoutStrategy()); diagram.LayoutSettings.DefaultLayoutStrategyId = "default"; var state = new LayoutState(diagram) { BoxSizeFunc = dataId => boxContainer.BoxesByDataId[dataId].Size }; LayoutAlgorithm.Apply(state); Assert.AreEqual(5, diagram.VisualTree?.Depth); }
private void StartLayout(bool resetBoxes) { TextLayoutTimeElapsed.Text = string.Empty; // release any existing progress on background layout m_progressWaitHandle?.Dispose(); m_progressWaitHandle = new AutoResetEvent(true); // re-create source data, diagram and layout data structures if (resetBoxes || m_diagram == null) { m_dataSource = new TestDataSource(); new TestDataGen().GenerateDataItems((TestDataSource)m_dataSource, 200, 5); //m_dataSource = new DebugDataSource(); //await ((DebugDataSource)m_dataSource).Load(); var boxContainer = new BoxContainer(m_dataSource); TestDataGen.GenerateBoxSizes(boxContainer); //await ((DebugDataSource)m_dataSource).ApplyState(boxContainer); foreach (var box in boxContainer.BoxesById.Values) { if (!box.IsSpecial) { box.IsCollapsed = true; } } m_diagram = new Diagram { Boxes = boxContainer }; m_diagram.LayoutSettings.LayoutStrategies.Add("linear", new LinearLayoutStrategy { ParentAlignment = BranchParentAlignment.Center }); m_diagram.LayoutSettings.LayoutStrategies.Add("hanger", new MultiLineHangerLayoutStrategy { ParentAlignment = BranchParentAlignment.Center }); m_diagram.LayoutSettings.LayoutStrategies.Add("singleColumn", new SingleColumnLayoutStrategy { ParentAlignment = BranchParentAlignment.Left }); m_diagram.LayoutSettings.LayoutStrategies.Add("fishbone1", new MultiLineFishboneLayoutStrategy { ParentAlignment = BranchParentAlignment.Center, MaxGroups = 1 }); m_diagram.LayoutSettings.LayoutStrategies.Add("fishbone2", new MultiLineFishboneLayoutStrategy { ParentAlignment = BranchParentAlignment.Center, MaxGroups = 2 }); m_diagram.LayoutSettings.LayoutStrategies.Add("hstack1", new StackingLayoutStrategy { Orientation = StackOrientation.SingleRowHorizontal }); m_diagram.LayoutSettings.LayoutStrategies.Add("vstack1", new StackingLayoutStrategy { Orientation = StackOrientation.SingleColumnVertical }); m_diagram.LayoutSettings.LayoutStrategies.Add("assistants", new FishboneAssistantsLayoutStrategy { ParentAlignment = BranchParentAlignment.Center }); m_diagram.LayoutSettings.DefaultLayoutStrategyId = "hanger"; m_diagram.LayoutSettings.DefaultAssistantLayoutStrategyId = "assistants"; //m_diagram.LayoutSettings.BranchSpacing = 5; } var state = new LayoutState(m_diagram); if (CbInteractiveMode.IsChecked.GetValueOrDefault(false)) { state.BoundaryChanged += StateBoundaryChanged; } state.OperationChanged += StateOperationChanged; state.LayoutOptimizerFunc = LayoutOptimizer; Task.Factory.StartNew(() => { m_timer = Stopwatch.StartNew(); LayoutAlgorithm.Apply(state); m_timer.Stop(); Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TextLayoutTimeElapsed.Text = m_timer.Elapsed.ToString(); }); }) .ContinueWith( (prev, s) => { m_progressWaitHandle.Dispose(); m_progressWaitHandle = null; }, null, TaskContinuationOptions.None); }