Line | Hits | Source |
---|---|---|
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 | { | |
33 | 0 | super(); |
34 | 0 | if (min_size < 0 || max_size < 0) |
35 | 0 | throw new IllegalArgumentException("sizes must be non-negative"); |
36 | 0 | if (min_size > max_size) |
37 | 0 | throw new IllegalArgumentException("min_size must be <= max_size"); |
38 | 0 | this.min = 0; |
39 | 0 | this.max = 0; |
40 | 0 | this.nvv = nvv; |
41 | 0 | setMinSize(min_size); |
42 | 0 | setMaxSize(max_size); |
43 | 0 | } |
44 | ||
45 | public int getSize(Vertex v) | |
46 | { | |
47 | 0 | Number n = nvv.getNumber(v); |
48 | 0 | double value = min; |
49 | 0 | if (n != null) |
50 | 0 | value = n.doubleValue(); |
51 | 0 | min = Math.min(this.min, value); |
52 | 0 | max = Math.max(this.max, value); |
53 | ||
54 | 0 | if (min == max) |
55 | 0 | 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 | |
59 | 0 | return min_size + (int)(((value - min) / (max - min)) * size_diff); |
60 | } | |
61 | ||
62 | public void setMinSize(int min_size) | |
63 | { | |
64 | 0 | this.min_size = min_size; |
65 | 0 | } |
66 | ||
67 | public void setMaxSize(int max_size) | |
68 | { | |
69 | 0 | this.size_diff = max_size - this.min_size; |
70 | 0 | } |
71 | ||
72 | public void setNumberVertexValue(NumberVertexValue nvv) | |
73 | { | |
74 | 0 | this.nvv = nvv; |
75 | 0 | } |
76 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |