protected override void PlaceObjects(IEnumerable <Dependency> dependencies) { IEnumerable <Item> items = dependencies.SelectMany(e => new[] { e.UsingItem, e.UsedItem }).Distinct(); double deltaAngle = 2 * Math.PI / items.Count(); Func <int, double> r = items.Any(i => i.Name.StartsWith("star")) ? i => 100.0 + (i % 2 == 0 ? 60 : 0) : items.Any(i => i.Name.StartsWith("spiral")) ? (Func <int, double>)(i => 80.0 + 20 * i) : /*circle*/ i => 100; int n = 0; var boxes = new Dictionary <Item, IBox>(); foreach (var i in items) { int k = n++; double phi = k * deltaAngle; // Define position in polar coordinates with origin, radius (r) and angle (ohi). var pos = new VariableVector("pos_" + k, Solver, r(k) * Math.Sin(phi), r(k) * Math.Cos(phi)); boxes[i] = Box(pos, i.Name, B(i.Name).Restrict(F(null, 15), F(null, 15)), borderWidth: 2); } foreach (var d in dependencies) { IBox from = boxes[d.UsingItem]; IBox to = boxes[d.UsedItem]; if (d.Ct > 0 && !Equals(d.UsingItem, d.UsedItem)) { Arrow(from.GetBestConnector(to.Center), to.GetBestConnector(from.Center), 1, text: "#=" + d.Ct, textLocation: 0.2); } } }
public void TestSingleAnchor() { CreateAndRender(r => { IBox box = r.Box(r.F(100, 100), "B", r.F(70, 200), borderWidth: 10, textFont: new Font(FontFamily.GenericSansSerif, 20)); VariableVector far = r.F(300, 400); r.Arrow(box.Center, far, width: 5, color: Color.Blue); // center to far point r.Arrow(box.Center, r.F(400, 400), width: 2, color: Color.Green); // 45° diagonal from center r.Arrow(box.GetBestConnector(far), far, width: 10, color: Color.Brown); // anchor to far point }, new GlobalContext()); }
private void ArrowToInterfaceBox(IBox fromBox, IBox toBox, VariableVector fromPos, Dependency d, string prefix) { VariableVector toPos = toBox.GetBestConnector(fromPos).WithYOf(fromPos); fromPos = fromBox.GetBestConnector(toPos).WithYOf(fromPos); Arrow(fromPos, toPos, 1, color: d.NotOkCt > 0 ? Color.Red : d.QuestionableCt > 0 ? Color.Blue : Color.Black, text: prefix + "#=" + d.Ct, textLocation: -20, textFont: _lineFont, fixingOrder: 2, edgeInfo: d.ExampleInfo); toBox.UpperLeft.MinY(fromPos.Y + 5); toBox.LowerLeft.MaxY(fromPos.Y - toBox.TextBox.Y); }