예제 #1
0
        /*
         * Colors cells and returns assigned colors
         */
        public Dictionary <AST.Address, System.Drawing.Color> DrawClustersWithHistogram(HashSet <HashSet <AST.Address> > clusters, ROInvertedHistogram ih, Worksheet ws, Graph g, bool colorFormulas)
        {
            // output
            var d = new Dictionary <AST.Address, System.Drawing.Color>();

            // Disable screen updating
            var initial_state = _app.ScreenUpdating;

            _app.ScreenUpdating = false;

            // clear colors
            ClearAllColors(ws);

            // init cluster color map
            ClusterColorer clusterColors = new ClusterColorer(clusters, 0, 360, 180 + 50, ih, g);

            // do we stumble across protected cells along the way?
            var protCells = new List <AST.Address>();

            // size of biggest cluster
            var maxsz = clusters.Select(c => c.Count).Max();

            // order clusters
            var clusters_o = clusters.OrderBy(hs =>
            {
                var first = hs.First();
                if (!g.isFormula(first))
                {
                    return(0);
                }
                else
                {
                    return(maxsz - hs.Count);
                }
            }).ToArray();

            // paint
            foreach (var cluster in clusters_o)
            {
                System.Drawing.Color c = clusterColors.GetColor(cluster);

                foreach (AST.Address addr in cluster)
                {
                    if (!paintColor(addr, c, colorFormulas))
                    {
                        protCells.Add(addr);
                    }
                    // keep track of color
                    d.Add(addr, c);
                }
            }

            // warn user if we could not highlight something
            if (protCells.Count > 0)
            {
                var names = String.Join(", ", protCells.Select(c => c.A1Local()));
                System.Windows.Forms.MessageBox.Show("WARNING: This workbook contains the following protected cells that cannot be highlighted:\n\n" + names);
            }

            // Enable screen updating
            _app.ScreenUpdating = initial_state;

            return(d);
        }