Created
August 31, 2008 22:59
-
-
Save kueda/8230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment