[flexcoders] Help with a smarter custom LabelRenderer

2009-03-02 Thread sbeausol

I've been able to successfully implement Ely's Custom LabelRenderer for
my own purposes (Custom LabelRenderer
http://www.quietlyscheming.com/blog/charts/chart-sampler/ ) however I
was hoping to make it smarter.  In my app, I have a Line Chart with my
primary piece of data being modified LineSeries (basically a vertical
line series to plot a spectrum so its a line starting at x,y values and
drawn down to the x-axis) and 3-4 plotseries.  My labelRenderer has been
customized to label points from the the plot series I add.  The label is
a string about 2-3 chars long, however the nature of my lineseries chart
is such that some line ends up intersecting my labels, and some labels
actually overlap making for a relatively cluttered look.  What I was
hoping to do within the labelrenderer is to find out if I have any
points near the point I am labeling, and adjust my labels when needed. 
I played a bit with the findDataPoints function within the chart object,
but I'm not 100% sure what I'm doing and it seems as though if I ever
return and hits they are all from the same series and never include
other series hits.  Am I on the right track?  I am guessing i need to
customize the findAllDatapoints function but I'm not sure where to

Any input is appreciated...

a demo of the app is here:

here is the labelRenderer:

 import flash.display.Graphics;
 import flash.geom.Point;
 import flash.geom.Rectangle;

 import mx.charts.ChartItem;
 import mx.charts.LineChart;
 import mx.charts.series.PlotSeries;
 import mx.charts.series.items.PlotSeriesItem;
 import mx.controls.Label;
 import mx.core.IDataRenderer;
 import mx.core.UIComponent;

 public class LabelRenderer extends UIComponent implements
 private var _label:Label;

 public function LabelRenderer()
 _label = new Label();
 private var _chartItem:ChartItem;
 private var _chart:LineChart;

 public function get data():Object
 return _chartItem;

 public function set data(value:Object):void
 if (_chartItem == value)
 _chartItem = ChartItem(value);
 var out:String;
 if (_chartItem != null) {
 if (this.data.item.bmatch ==
PlotSeriesItem(_chartItem).xNumber) {
 out = b+value.item.Nnum;
 _label.text = out;
 _label.setStyle(color, 0x0066FF);
 fill = fills[0];
 else if (this.data.item.ymatch ==
PlotSeriesItem(_chartItem).xNumber) {
 out = y+value.item.Cnum;
 _label.text = out;
 _label.setStyle(color, 0xFF0033);
 fill = fills[1];

 private static const fills:Array = [0x0066FF,0xFF0033];
 private var fill:Number;

override protected function
unscaledHeight:Number):void {

super.updateDisplayList(width, height);

//var fill:Number = fills[5];

//var rc:Rectangle = new Rectangle(0,0, width, height);

var series:PlotSeries = PlotSeries(this.parent);
 _chart = LineChart(series.owner);
 var pt:Point = _chart.contentToLocal(new
 //var array:Array =
 var array:Array = _chart.findDataPoints(pt.x,pt.y);
 trace(checking for points around
+PlotSeriesItem(_chartItem).x+,+PlotSeriesItem(_chartItem).y+ peak
 trace(checking for points around +pt+ peak
 //checking to see if anything on our chart is within the
width of the label, if so we can move it
 if (array.length 1) {
 trace(found some stuff overlapping with my chartItem:
var rc:Rectangle = new Rectangle(2.5,3.5, 5,5);

var g:Graphics = graphics;
g.moveTo(rc.left, rc.top);
g.lineTo(rc.right, rc.top);
g.lineTo(rc.right, rc.bottom);
g.lineTo(rc.left, rc.bottom);
g.lineTo(rc.left, rc.top);

[flexcoders] help with datagrid cell custom itemrenderer

2009-02-15 Thread sbeausol

I've been able to implement a custom Text Color Item Renderer for a
datagrid based off of this post Custom item renderer
tml  .  I've added 2 classes, a ComputedStylesColumn and
ComputedStylesRenderer and I can successfully implement this in the mxml
file, but I was hoping to build my datagrids dynamically with

the mxml that works:
mx:DataGrid id=dg1 initialize=dg1.dataProvider = dp paddingTop=0
paddingBottom=0 verticalAlign=middle 
mx:DataGridColumn headerText=Name dataField=name width=140/
mx:DataGridColumn headerText=Symbol dataField=symbol width=60 /
local:ComputedStylesColumn headerText=Price dataField=price
itemRenderer=ComputedStylesRenderer /

I've been able to reconstruct most things in actionscript except for the

when I try this:
var custColumn1:ComputedStylesColumn = new ComputedStylesColumn();
custColumn1.dataField = price;
custColumn1.headerText = Price;
custColumn1.width = 75;
custColumn1.stylesFunction = computeStyles;

Everything works except:

custColumn1.itemRenderer = ComputedStylesRenderer();
Implicit coercion of a value of type ComputedStylesRenderer to an
unrelated type mx.core:IFactory