コード例 #1
0
        public TreemapChart Build(double left, double top, double width, double height)
        {
            ChartArea = new Rect(left, top, width, height);

            BuildArea();
            BuildTitle(Parameters);
            BuildLegend(Parameters);

            if (Parameters.Algorithm == TreemapAlgorithm.Circular)
            {
                double edge    = Math.Min(PlotArea.Width, PlotArea.Height);
                double excessX = (PlotArea.Width - edge) / 2;
                double excessY = (PlotArea.Height - edge) / 2;
                PlotArea = new Rect(PlotArea.X + excessX, PlotArea.Y + excessY, edge, edge);
            }

            if (IsChartDegenerated())
            {
                return(this);
            }

            Parent                 = new TreemapItem(PlotArea.Left, PlotArea.Top, PlotArea.Width, PlotArea.Height);
            Parent.Size            = Sizes.Sum();
            Parent.IndexParameters = new TreemapIndex()
            {
                LineVisible = false,
                LineWeight  = 0
            };

            IndexesComparer    comparer = new IndexesComparer();
            List <TreemapItem> items    = new List <TreemapItem>()
            {
                Parent
            };

            for (int i = 0; i < Indexes.Count; i++)
            {
                List <TreemapData> data = GetDepthData(i);

                foreach (TreemapItem item in items)
                {
                    List <TreemapData> itemData = data.Where(d => comparer.Equals(d.Indexes.Take(i).ToList(), item.Indexes)).ToList();
                    item.ApplyAlgorithm(itemData, Parameters.Algorithm);
                }

                items = items.SelectMany(item => item.Items).ToList();

                SetTreemapItemsParameters(i, items);
            }

            return(this);
        }