// zoom in on a parent level
        private void ZoomIn(object node)
        {
            _zoomedIn = true;

            // get parent node
            string      parentName = (node as TreemapNode).Hierarchy;
            TreemapNode parentNode = _hierarchicalData.First(s => s.NodeName == parentName);

            hierarchyLevelTextBlock.Text = String.Format("Showing: {0}", parentName);

            // clear canvas and row collections ready for drawing the zoomed in view
            canvas.Children.Clear();
            _rows.Clear();

            // reset the drawing area bounds
            _drawingArea.Height = canvas.ActualHeight;
            _drawingArea.Width  = canvas.ActualWidth;

            // reset the offsets as we are starting from x0y0
            _offsetX = 0;
            _offsetY = 0;

            // update the normalised values and re-squarify/redraw
            ZoomNormalisedValues(parentNode.Children);
            Squarify(parentNode.Children, new List <TreemapNode>());
            DrawZoomedInView();
        }
        // Method that normalises the areas to the screen space
        private void NormaliseValues()
        {
            double total            = 0;
            double area             = 0;
            double screenScaleRatio = 0;

            foreach (string[] element in _datasetModel.Dataset)
            {
                if (!double.TryParse(element[_areasIndex], out area))
                {
                    // Output error
                }
                else
                {
                    total += area;
                }
            }

            // Calculate the screen scale ratio
            screenScaleRatio = _drawingArea.Width * _drawingArea.Height / total;

            foreach (string[] element in _datasetModel.Dataset)
            {
                double initialValue = double.Parse(element[_areasIndex]);
                double scaledValue  = initialValue * screenScaleRatio;

                TreemapNode node = new TreemapNode();
                node.NormalisedArea = scaledValue;
                node.Name           = element[_idIndex];
                node.Value          = element[_areasIndex];
                if (_descriptionIndex >= 0)
                {
                    node.Description = element[_descriptionIndex];
                }
                node.Hierarchy   = element[_hierarchyIndex];
                node.ColourValue = element[_colourIndex];

                _hierarchicalData.Add(node);
            }

            CreateHierarchy();
            AggregateHierarchyValues();
            SortValues();
            Squarify(_hierarchicalData, new List <TreemapNode>());

            // squarify children
            foreach (TreemapNode node in _hierarchicalData)
            {
                _offsetChildX = node.XPos;
                _offsetChildY = node.YPos;
                SquarifyChildren(node.Children, new List <TreemapNode>(), node.NodeWidth, node.NodeHeight);
            }

            DrawChildren();
            Draw();
        }
Exemplo n.º 3
0
        // Method that normalises the areas to the screen space
        private void NormaliseValues()
        {
            double total            = 0;
            double area             = 0;
            double screenScaleRatio = 0;

            foreach (string[] element in _datasetModel.Dataset)
            {
                if (!double.TryParse(element[_areasIndex], out area))
                {
                    // Output error
                }
                else
                {
                    total += area;
                }
            }

            // Calculate the screen scale ratio
            screenScaleRatio = _drawingArea.Width * _drawingArea.Height / total;

            foreach (string[] element in _datasetModel.Dataset)
            {
                double initialValue = double.Parse(element[_areasIndex]);
                double scaledValue  = initialValue * screenScaleRatio;

                TreemapNode node = new TreemapNode();
                node.NormalisedArea = scaledValue;
                node.NodeName       = element[_idIndex];
                node.Value          = element[_areasIndex];
                if (_descriptionIndex >= 0)
                {
                    node.Description = element[_descriptionIndex];
                }
                node.ColourValue = element[_colourIndex];
                _treemapNodes.Add(node);
            }

            SortValues();
            Squarify(_treemapNodes, new List <TreemapNode>());
            Draw();
        }
Exemplo n.º 4
0
 public void AddNodeToRow(TreemapNode node)
 {
     _nodes.Add(node);
 }
Exemplo n.º 5
0
 public void AddNodeToRow(TreemapNode node)
 {
     _nodes.Add(node);
 }
        // Method that normalises the areas to the screen space
        private void NormaliseValues()
        {
            double total = 0;
            double area = 0;
            double screenScaleRatio = 0;

            foreach (string[] element in _datasetModel.Dataset)
            {
                if (!double.TryParse(element[_areasIndex], out area))
                {
                    // Output error
                }
                else
                {
                    total += area;
                }
            }

            // Calculate the screen scale ratio
            screenScaleRatio = _drawingArea.Width * _drawingArea.Height / total;

            foreach (string[] element in _datasetModel.Dataset)
            {
                double initialValue = double.Parse(element[_areasIndex]);
                double scaledValue = initialValue * screenScaleRatio;

                TreemapNode node = new TreemapNode();
                node.NormalisedArea = scaledValue;
                node.NodeName = element[_idIndex];
                node.Value = element[_areasIndex];
                if (_descriptionIndex >= 0)
                {
                    node.Description = element[_descriptionIndex];
                }
                node.ColourValue = element[_colourIndex];
                _treemapNodes.Add(node);
            }

            SortValues();
            Squarify(_treemapNodes, new List<TreemapNode>());
            Draw();
        }
        // Method that normalises the areas to the screen space
        private void NormaliseValues()
        {
            double total = 0;
            double area = 0;
            double screenScaleRatio = 0;

            foreach (string[] element in _datasetModel.Dataset)
            {
                if (!double.TryParse(element[_areasIndex], out area))
                {
                    // Output error
                }
                else
                {
                    total += area;
                }
            }

            // Calculate the screen scale ratio
            screenScaleRatio = _drawingArea.Width * _drawingArea.Height / total;

            foreach (string[] element in _datasetModel.Dataset)
            {
                double initialValue = double.Parse(element[_areasIndex]);
                double scaledValue = initialValue * screenScaleRatio;

                TreemapNode node = new TreemapNode();
                node.NormalisedArea = scaledValue;
                node.Name = element[_idIndex];
                node.Value = element[_areasIndex];
                if (_descriptionIndex >= 0)
                {
                    node.Description = element[_descriptionIndex];
                }
                node.Hierarchy = element[_hierarchyIndex];
                node.ColourValue = element[_colourIndex];

                _hierarchicalData.Add(node);
            }

            CreateHierarchy();
            AggregateHierarchyValues();
            SortValues();
            Squarify(_hierarchicalData, new List<TreemapNode>());

            // squarify children
            foreach (TreemapNode node in _hierarchicalData)
            {
                _offsetChildX = node.XPos;
                _offsetChildY = node.YPos;
                SquarifyChildren(node.Children, new List<TreemapNode>(), node.NodeWidth, node.NodeHeight);
            }

            DrawChildren();
            Draw();
        }