Example #1
0
        protected override void Paint(DrawingContext context)
        {
            //VisualNode visNode = (VisualNode)VisualItem;
            //var tree = visNode.Graph.GetSpanningTree(0);

            string label = GetLabel();

            var formattedText = new FormattedText(label,
                                                  new System.Globalization.CultureInfo("en-us"), FlowDirection.LeftToRight,
                                                  new Typeface(new FontFamily("Arial"), FontStyles.Normal,
                                                               FontWeights.Normal, FontStretches.Normal), TextSize, Brushes.DarkBlue)
            {
                //LineHeight = lineHeight,
                TextAlignment = TextAlignment.Center
            };

            double NodeWidth  = Math.Max(NodeMinWidth, formattedText.Width);
            double NodeHeight = Math.Max(NodeMinHeight, formattedText.Height);

            var userLableType = _dataScheme.GetUserLabelType(_dataNode);
            int correctCnt, totalCnt;

            _dataScheme.GetCorrectDocCount(_dataNode, out correctCnt, out totalCnt);
            var correctRatio = totalCnt == 0 ? 0 : ((double)correctCnt / totalCnt);
            var pen          = userLableType == UserLabelType.Relevant ? new Pen(Brushes.Red, 3) : userLableType == UserLabelType.Mixed ? new Pen(Brushes.Yellow, 2) : new Pen(Brushes.Black, 1);
            var brush        = new SolidColorBrush()
            {
                Color = Lava.Util.InterpolatorLib.Interp(Colors.White, Colors.Red, correctRatio)
            };

            context.DrawRectangle(brush, pen,
                                  new Rect(-NodeWidth * 0.5, -NodeHeight * 0.5, NodeWidth, NodeHeight));
            context.DrawText(formattedText, new Point(0, -NodeHeight * 0.5));

            if (VisualItem.Hover)
            {
                var formattedText2 = new FormattedText(GetTooltipString(),
                                                       new System.Globalization.CultureInfo("en-us"), FlowDirection.LeftToRight,
                                                       new Typeface(new FontFamily("Arial"), FontStyles.Normal,
                                                                    FontWeights.Normal, FontStretches.Normal), TextSize, Brushes.Black)
                {
                    //LineHeight = lineHeight,
                    TextAlignment = TextAlignment.Center,
                    MaxTextWidth  = 200
                };
                double NodeWidth2  = Math.Max(NodeMinWidth, formattedText2.Width);
                double NodeHeight2 = Math.Max(NodeMinHeight, formattedText2.Height);
                context.DrawRectangle(Brushes.LightYellow, null,
                                      new Rect(0, 0, NodeWidth2 + 10, NodeHeight2));
                context.DrawText(formattedText2, new Point(0, 0));
            }

            int layer = VisualItem.Hover ? 100 : 10;

            if (VisualItem.Layer != layer)
            {
                VisualItem.Layer = layer;
            }
        }