コード例 #1
0
ファイル: MultilevelBowTie.cs プロジェクト: wshanshan/DDD
        /// <summary>
        /// Recursively generates the wedges for each node in the hierarchical value tree.
        /// </summary>
        /// <param name="node">The node from which to create a wedge.</param>
        /// <param name="innerRadius">The inner radius of the wedge.</param>
        /// <param name="radius">The radius length (poor naming!).</param>
        /// <param name="arc">The arc of the wedge.</param>
        /// <param name="rotationalAngle">The rotational angle of the wedge (rotational transform, essentially).</param>
        private void generate(HierarchicalValue node, double innerRadius, double radius, double arc, double rotationalAngle)
        {
            Wedge wedge = new Wedge();

            wedge.center = center;
            wedge.innerRadius = innerRadius;
            wedge.outerRadius = innerRadius + radius;
            wedge.sweep = arc;
            wedge.rotationAngle = rotationalAngle;

            //use a default black stroke around each wedge
            wedge.Stroke = System.Windows.Media.Brushes.Black;
            wedge.StrokeThickness = 0.5;
            wedge.Fill = brushes[node.tag]; //lookup the unique color based on the tag for this node
            wedge.ToolTip = node.name;

            wedges.Add(wedge);

            //arc percentage for children...
            var h = rotationalAngle;

            if (rotationalAngle < 180.0)
            {
                //create wedges for all of the children of this node
                foreach (HierarchicalValue child in node.children)
                {
                    //sweep is related to the value the child contributes to the parent value
                    var angle = arc * (child.totalValues() / (node.totalValues() - node.value));
                    generate(child, wedge.outerRadius, radius, angle, h);
                    h += angle; //advance around the parent's arc
                }
            }
            else {
                // Process in reverse order
                //create wedges for all of the children of this node
                for(int i = node.children.Count - 1;i >= 0;i--)
                {
                    HierarchicalValue child = node.children[i];

                    //sweep is related to the value the child contributes to the parent value
                    var angle = arc * (child.totalValues() / (node.totalValues() - node.value));
                    generate(child, wedge.outerRadius, radius, angle, h);
                    h += angle; //advance around the parent's arc
                }
            }
        }