Coverage details for edu.uci.ics.jung.graph.decorators.InterpolatingVertexSizeFunction

LineHitsSource
1 /*
2  * Created on Nov 3, 2005
3  *
4  * Copyright (c) 2005, the JUNG Project and the Regents of the University
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.graph.decorators;
13  
14 import edu.uci.ics.jung.graph.Vertex;
15  
16 /**
17  * Provides vertex sizes that are spaced proportionally between
18  * min_size and max_size depending on
19  *
20  * @author Joshua O'Madadhain
21  */
22 public class InterpolatingVertexSizeFunction implements VertexSizeFunction
23 {
24     protected double min;
25     protected double max;
26     protected NumberVertexValue nvv;
27     protected int min_size;
28     protected int size_diff;
29     
30     public InterpolatingVertexSizeFunction(NumberVertexValue nvv,
31             int min_size, int max_size)
32     {
330        super();
340        if (min_size < 0 || max_size < 0)
350            throw new IllegalArgumentException("sizes must be non-negative");
360        if (min_size > max_size)
370            throw new IllegalArgumentException("min_size must be <= max_size");
380        this.min = 0;
390        this.max = 0;
400        this.nvv = nvv;
410        setMinSize(min_size);
420        setMaxSize(max_size);
430    }
44  
45     public int getSize(Vertex v)
46     {
470        Number n = nvv.getNumber(v);
480        double value = min;
490        if (n != null)
500            value = n.doubleValue();
510        min = Math.min(this.min, value);
520        max = Math.max(this.max, value);
53         
540        if (min == max)
550            return min_size;
56         
57         // interpolate between min and max sizes based on how big value is
58         // with respect to min and max values
590        return min_size + (int)(((value - min) / (max - min)) * size_diff);
60     }
61     
62     public void setMinSize(int min_size)
63     {
640        this.min_size = min_size;
650    }
66  
67     public void setMaxSize(int max_size)
68     {
690        this.size_diff = max_size - this.min_size;
700    }
71     
72     public void setNumberVertexValue(NumberVertexValue nvv)
73     {
740        this.nvv = nvv;
750    }
76 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.