Hi Tracy,
This is an interesting idea...but you have me at a bit of a
loss....I was already heading down part of the same path you laid out
here...here is my renderer code thus far:
First, the column from my ADG:
<mx:AdvancedDataGridColumn id="groupedHVR1" dataField="Hvr1M"
headerText="HVR1 Mutations" headerWordWrap="true" textAlign="left"
wordWrap="true" editable="false" width="100" showDataTips="true"
itemRenderer="renderers.GeneralRenderers.AminoAcidRenderer" />
now the AminoAcidRenderer.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.core.IFactory" truncateToFit="true"
width="100%" height="100%" paddingLeft="2" paddingRight="2">
<mx:Script>
<![CDATA[
import mx.utils.ObjectProxy;
override public function set text(value:String):void
{
if (value != null && value != " " && value != "")
{
value = String(value.replace("G",'<font
color="black">G</font>'));
value = String(value.replace("A",'<font
color="green">A</font>'));
value = String(value.replace("T",'<font
color="red">T</font>'));
value = String(value.replace("C",'<font
color="blue">C</font>'));
super.htmlText = value;
}
else
{
super.htmlText = value;
}
}
public function newInstance():*
{
return new AminoAcidRenderer();
}
]]>
</mx:Script>
</mx:Label>
But, alas, there are a couple of problems here. First, the
string.replace() only affects the first occurrence of the pattern and
not every occurrence (I wonder if a regex would remedy that?). Then
although the substitution gets done for those patterns that are found,
the htmlText isn't getting rendered...and I wonder if it's due to the
function set text instead of function set htmlText, which I tried and
literally got nothing.
I've also looked at the TextRange that someone else suggested but
not sure how to possibly use that as it needs a begin/end index and the
letters are sporadic from one string to the next.
How would I setup the labelFunction to parse the string to get the
letters?
Thanks in advance!
Adrian
Tracy Spratt wrote:
I suggest that you use a labelFunction feeding a renderer that uses
htmlText. The label function would simply parse the strings to get
the letters, and wrap them in a Font tag specifying the color. This
would be very easy.
Tracy Spratt,
Lariat Services, development services available
------------------------------------------------------------------------
*From:* flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com]
*On Behalf Of *valdhor
*Sent:* Wednesday, April 22, 2009 4:44 PM
*To:* flexcoders@yahoogroups.com
*Subject:* [flexcoders] Re: RegEx string via cell ItemRenderer to
colorize specific characters or a better method?
Have a look into TextRange.
--- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>, Adrian Williams <adri...@...>
wrote:
>
> Hi All,
>
> Here's a fun one!
>
> I have a column in an ADG, and the cells can contain a variety of
> data including:
>
> 16223T,16290T,16319A,16362C,16524G
> or
> 73G,249-,263G,290-,291-,309.1C,315.1C,489C,493G,522-,523-
>
> What I need to do is for each of the letters (there's four possible
> - A,T,C,G) I need to be able to change the font color specific to each
> letter...i.e. all the "A's" need to be green, the "C's" need to be blue,
> the "G's" need to be black and the "T's" need to be red.
>
> As I've been thinking about it, I figure I'm going to have to use a
> custom itemRenderer for the cell to manipulate the data to begin with.
> But within the renderer, I'm quasi-stuck. I figure the simplest way to
> ID the letters is to RegExp the data...then possibly using a switch/case
> to set the colors for the letters...but not sure how to affect just the
> individual letters in the overall string and then return that with the
> cell's renderer??
>
> Anyone have any thoughts on this?
>
> Thanks!
> Adrian
>