// Does one pass of arranging the images into clusters.  Returns the longest cluster.
        private double arrangeHelper(int start, int end, double aveWidth, double unitLength)
        {
            // The space one image should take in terms of year count.
            double interval_width = Math.Ceiling(aveWidth / unitLength);

            // Dividee the overall space into small parts based on the year and keep track of the availability of the spaces.
            Dictionary<int, ImageCluster> space = new Dictionary<int, ImageCluster>();
            ImageCluster prevCluster = null;
            double rightPos = 1;
            foreach (ImageData img in _displayedCollection)
            {
                // The index of the chunk of timeline space that contains the year of this image.
                int index = (int)((img.year - start) / interval_width);
                ImageCluster cluster = null;
                if (!space.ContainsKey(index))
                {
                    Boolean collide = false;
                    // Check if the new cluster would collide with the previous cluster. If so, add to the previous cluster instead.
                    if (prevCluster != null)
                    {
                        if (index * aveWidth <= Canvas.GetLeft(prevCluster) + prevCluster.longestRowWidth())
                        {
                            collide = true;
                            cluster = prevCluster;
                        }
                    }

                    // Add a new cluster.
                    if (!collide)
                    {
                        cluster = new ImageCluster(ROWS);
                        space.Add(index, cluster);
                        MainCanvas.Children.Add(cluster);
                        Canvas.SetLeft(cluster, index * aveWidth);
                    }
                }
                else
                {
                    cluster = space[index];
                }
                cluster.addImage(img);
                prevCluster = cluster;

                // Center the cluster by shifting it left by half the width.
                //Canvas.SetLeft(cluster, Canvas.GetLeft(cluster) - cluster.longestRowWidth() / 2.0);

                //keep track of rightmost point to appropriately scale maincanvas
                rightPos = Canvas.GetLeft(cluster) + cluster.longestRowWidth();
            }

            MainCanvas.Width = rightPos;
            mainScatterViewItem.Width = MainCanvas.Width + _windowSize.Width;

            double marginX = (mainScatterViewItem.Width - MainCanvas.Width) / 2;
            double marginY = (mainScatterViewItem.Height - MainCanvas.Height) / 2;
            MainCanvas.Margin = new Thickness(marginX, marginY, marginX, marginY);

            ImageCluster longest_cluster = null;
            // Find the longest cluster.
            foreach (ImageCluster ic in space.Values)
            {
                if (longest_cluster == null ||
                    longest_cluster.longestRowWidth() < ic.longestRowWidth())
                {
                    longest_cluster = ic;
                }
            }

            int diff = longest_cluster.maxYear - longest_cluster.minYear;
            diff = (diff == 0) ? 1 : diff;
            return (double)longest_cluster.getSize() / ((double)ROWS) * aveWidth / ((double) diff);
        }
Esempio n. 2
0
 public void setCluster(ImageCluster c)
 {
     _cluster = c;
 }