Пример #1
0
        /// <summary>
        /// Updates the labels of a given owner.
        /// </summary>
        /// <param name="graph">The graph the owner belongs to.</param>
        /// <param name="labelDefaults">The defaults to create the labels with.</param>
        /// <param name="item">The owner of the label.</param>
        /// <param name="labelData">The data to create the labels from.</param>
        private static void UpdateLabels(IGraph graph, ILabelDefaults labelDefaults, ILabelOwner item, object labelData)
        {
            var labels = item.Labels;

            if (labelData == null)
            {
                while (labels.Count > 0)
                {
                    graph.Remove(labels[labels.Count - 1]);
                }
            }
            else if (labels.Count == 0)
            {
                var layoutParameter = labelDefaults.GetLayoutParameterInstance(item);
                var labelStyle      = labelDefaults.GetStyleInstance(item);
                graph.AddLabel(item, labelData.ToString(), layoutParameter, labelStyle, null, labelData);
            }
            else if (labels.Count > 0)
            {
                var label = labels[0];
                if (label.Text != labelData.ToString())
                {
                    graph.SetLabelText(label, labelData.ToString());
                }
                if (label.Tag != labelData)
                {
                    label.Tag = labelData;
                }
            }
        }
        /// <summary>
        /// Copy one edge label.
        /// </summary>
        /// <param name="pageView">The view (i.e. target) graph.</param>
        /// <param name="edgeLabelLayout">The layout of the label.</param>
        /// <param name="modelLabel">The original label.</param>
        /// <param name="viewEdge">The copied edge (from the view graph).</param>
        /// <param name="labelDefaults"></param>
        /// <returns>The copied label.</returns>
        private ILabel CopyEdgeLabel(IGraph pageView, IEdgeLabelLayout edgeLabelLayout, ILabel modelLabel, IEdge viewEdge, ILabelDefaults labelDefaults)
        {
            // get the style from edgeLabelStyle property. If none is set get it from the original (model) label.
            ILabelStyle style = (ILabelStyle)(labelDefaults.Style != NullLabelStyle ?
                                              labelDefaults.GetStyleInstance(viewEdge) :
                                              modelLabel.Style.Clone());
            ILabelModelParameter parameter = labelDefaults.LayoutParameter != NullLabelModelParameter
                            ? labelDefaults.GetLayoutParameterInstance(viewEdge)
                            : (ILabelModelParameter)edgeLabelLayout.ModelParameter;

            // create a new label in the view graph using the style,
            // the text from the original label and the layout from the layout graph
            ILabel viewLabel = pageView.AddLabel(viewEdge, modelLabel.Text, parameter, style);

            viewLabel.Tag = modelLabel.Tag;
            return(viewLabel);
        }