kueda (owner)

Revisions

gist: 8230 Download_button fork
public
Public Clone URL: git://gist.github.com/8230.git
Embed All Files: show embed
WidthEncoder.as #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package
{
import flare.scale.ScaleType;
import flare.util.palette.Palette;
import flare.util.palette.SizePalette;
import flare.vis.data.Data;
import flare.vis.operator.encoder.Encoder;
 
/**
* Encodes a data field into size values, using a scale transform and a
* size palette to determines an item's scale. The target property of a
* WidthEncoder is assumed to be the <code>DataSprite.size</code> property.
*/
public class WidthEncoder extends Encoder
{
private var _palette:SizePalette;
 
/** @inheritDoc */
public override function get palette():Palette { return _palette; }
public override function set palette(p:Palette):void {
_palette = p as SizePalette;
}
/** The palette as a SizePalette instance. */
public function get sizes():SizePalette { return _palette; }
 
// --------------------------------------------------------------------
 
/**
* Creates a new WidthEncoder. By default, the scale type is set to
* a quantile scale grouped into 5 bins. Adjust the values of the
* <code>scale</code> property to change these defaults.
* @param source the source property
* @param group the data group to process
* @param palette the size palette to use. If null, a default size
* palette will be used.
*/
public function WidthEncoder(source:String=null,
group:String=Data.NODES, palette:SizePalette=null)
{
super(source, "w", group);
_binding.scaleType = ScaleType.TIME;
// _binding.bins = 10;
if (palette) {
_palette = palette;
} else {
_palette = new SizePalette();
// _palette.is2D = (group != Data.EDGES);
_palette.is2D = false;
}
}
 
/** @inheritDoc */
protected override function encode(val:Object):*
{
return _palette.getSize(_binding.interpolate(val));
}
 
} // end of class WidthEncoder
}