Skip to content

Instantly share code, notes, and snippets.

@kueda
Created August 31, 2008 22:59
Show Gist options
  • Save kueda/8230 to your computer and use it in GitHub Desktop.
Save kueda/8230 to your computer and use it in GitHub Desktop.
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