internal IEnumerable <KeyValuePair <string, Color> > GetNodeColors() { var depths = new Dictionary <string, Color>(); foreach (var node in this.nodes) { var brush = GraphResources.NodeColor(node.NodeIndex); depths.Add(node.Identifier, brush.Color); } return(depths); }
private void RefreshGraphNodes(SynthesizedGraph graph) { var parentCanvas = this.ParentCanvas; parentCanvas.Width = parentCanvas.Height = 0; if (graph == null || (graph.Nodes.Any() == false)) { return; // There is no graph or it's an empty graph. } var drawingContext = nodeVisuals.RenderOpen(); var textBrush = GraphResources.Brush(GraphResources.BrushIndex.NodeTextColor); // Font for use on node text. string fontResourceUri = "./Resources/Fonts/#Open Sans"; string pack = System.IO.Packaging.PackUriHelper.UriSchemePack; var uri = new Uri(pack + "://application:,,,/Bloodstone.Net;component/"); var textFontFamily = new FontFamily(uri, fontResourceUri); var typeface = new Typeface(textFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); Rect boundingBox = graph.Nodes.ElementAt(0).Rect; foreach (var node in graph.Nodes) { var rect = node.Rect; boundingBox.Union(rect); var bi = GraphResources.BrushIndex.NodeBorderColor; var bp = new Pen(GraphResources.Brush(bi), 1.0); rect.Offset(-0.5, -0.5); var fi = GraphResources.NodeColor(node.NodeIndex); drawingContext.DrawRectangle(fi, bp, rect); FormattedText ft = new FormattedText(node.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 10.0, textBrush) { Trimming = TextTrimming.CharacterEllipsis, TextAlignment = TextAlignment.Center }; rect = DeflateRectForText(ft, rect); drawingContext.DrawText(ft, rect.Location); } drawingContext.Close(); // Done drawing, commit changes. boundingBox.Inflate(Config.HorzGap, Config.VertGap); parentCanvas.Width = boundingBox.Width; parentCanvas.Height = boundingBox.Height; }
private void RenderSliderBackground(ScrollChangedEventArgs e) { var drawingContext = this.sliderBackground.RenderOpen(); var fillBrush = GraphResources.Brush(GraphResources.BrushIndex.SliderFill); var edgeBrush = GraphResources.Brush(GraphResources.BrushIndex.SliderEdge); var height = ParentCanvas.ActualHeight - 1.0; var edgeWidth = (Config.HorzGap + (0.5 * Config.NodeWidth)); var sliderWidth = e.ExtentWidth - edgeWidth - edgeWidth; // Fill the entire slider region with slider fill brush. Rect sliderRegion = new Rect(0.5 + edgeWidth, 0.5, sliderWidth, height); drawingContext.DrawRectangle(fillBrush, null, sliderRegion); drawingContext.Close(); }
private void RefreshGraphEdges(SynthesizedGraph graph) { if (graph == null || (graph.Edges.Any() == false)) { return; // There is no graph or it has no edges. } var nodes = graph.Nodes; var edgeData = new List <Tuple <int, Point, Point> >(); foreach (var edge in graph.Edges) { var startNode = nodes.First(n => n.Identifier == edge.StartNodeId); var endNode = nodes.First(n => n.Identifier == edge.EndNodeId); edgeData.Add(new Tuple <int, Point, Point>(startNode.NodeIndex, startNode.GetOutputPoint(edge.StartIndex), endNode.GetInputPoint(edge.EndIndex))); } // Edge outline in darker color (before drawing the fill). var eb = GraphResources.Brush(GraphResources.BrushIndex.EdgeOutlineColor); var drawingContext = edgeVisuals.RenderOpen(); foreach (var data in edgeData) { PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure() { StartPoint = data.Item2 }; AddBezier(pathFigure, data.Item2, data.Item3); pathGeometry.Figures.Add(pathFigure); var pb = GraphResources.NodeColor(data.Item1); drawingContext.DrawGeometry(null, new Pen(eb, 3.5), pathGeometry); drawingContext.DrawGeometry(null, new Pen(pb, 1.5), pathGeometry); var jointPen = new Pen(eb, 1.0); drawingContext.DrawEllipse(pb, jointPen, data.Item2, 4.0, 4.0); drawingContext.DrawEllipse(pb, jointPen, data.Item3, 4.0, 4.0); } drawingContext.Close(); }