Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Setting note color by derived attribute (Read 4477 times)
Rafter T. Sass
Full Member
*
Offline



Posts: 100
Burlington, VT
Setting note color by derived attribute
Feb 20th, 2013, 7:44pm
 
Hello -

I'm making a writing tool prototype, that sums its own words ($WordCount) and the words of all it's descendants (sum(descendants,$WordCount), and assigns the value to $TotalWords, compares it with a user-defined target value ($TargetWords); and calculates the proportion accomplished  ($TotalWords/$TargetWords) and assigns that value to $ProportionDone.

I'm trying to set note color according to $ProportionDone with this rule:
Code:
if($ProportionDone>=1) {$Color = "bright green;$NameBold="true"}
	else {	if($ProportionDone>=.75) {$Color = "green lighter"}
			else {if($ProportionDone>=.5) {$Color = "yellow lighter"}
					else {	if($ProportionDone>=.25) {$Color = "orange lighter"}
							else {	if($ProportionDone>=.25) {$Color = "red lighter"}}}}} 



Incidentally, I tried putting my long complex Display Expression and Rule into the text of other notes, to be evaluated with eval($Text(Note_Name) and couldn't get it to work at all. But that's a secondary goal... let's deal with it later. Wink

Any ideas on the note color challenge? Thanks!
Back to top
 
 
raughter   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Setting note color by derived attribute
Reply #1 - Feb 20th, 2013, 8:20pm
 
You forgot the closing quote on "bright green".

The modified colors are "lighter red," rather than "red lighter".

That should fix everything.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Setting note color by derived attribute
Reply #2 - Feb 21st, 2013, 4:03am
 
Also eval($Text(Note_Name) would need an extra closing ')' to work: eval($Text(Note_Name)). But, I doubt you need the eval() in the context you describe.

First, a corrected version of your expression, with added layout for clarity (now we'll use it stored in $Text) and a tweak to the last condition (explained in the notes below):
Code:
if($ProportionDone>=1) {
	$Color = "bright green";$NameBold="true";
} else {
	if($ProportionDone>=0.75) {
		$Color = "lighter green";
	} else {
		if($ProportionDone>=0.5) {
			$Color = "lighter yellow";
		} else {
			if($ProportionDone>=0.25) {
				$Color = "lighter orange";
			} else {
				$Color = "lighter red";
			}
		}
	}
};  


Notes:
  • The last two tests are both for $ProportionDone>=0.25. I suspect the last one should be for a figure less than 0.25 as that is everything else not already matching a previous test. As it is everything 'else' we don't need the last nested 'if' as every note in this last 'else' branch will have a $ProportionDone of less than 0.25 and so be coloured lighter red.
  • The ';' after the last } isn't strictly needed. However, if you then add more action code after the if cluase it helps to make plain to TB that you're starting a new piece of code.
  • If storing code like this in a note, first add the built-in "Code" prototype to your TBX and make a note using that prototype. Select/copy your code in the existing location and use paste and match style (Cmd+Opt+Shift+V) to paste the code into the note. You have a nice clear monospaced font making the code easier to read.
  • Don't forget to reset inheritance in any notes where to originally used code - e.g. where you typed it into the Rename dialog boxes. Select all those notes, open Inspector, Chose 'General' and 'DisplayExpression' from the pop-ups and then press the Use default button bottom left.
OK, so the new code is pasted into $Text of a (code) note. The note doesn't have to use the 'code' prototype but the latter just helps when writing/checking code. Now to use the code. Let's assume it's going to be the display expression for a prototype note "Task". Open the Rename dialog (of the code note) and give it this rule:

$DisplayExpression("Task") = $Text;

If you open the Rename for "Task" you'll see the code is added, though likely not all fitting in the visible area of the input box. TB ignores all the tabs you used in the original text layout, so while the code might look odd in the Rename box it works just fine.

The neat part is that you can now correct/refine the display expression of the Task note by editing the $Text of the code note. you don't even have to close the latter's text window, TB picks up the changes in the $Text and the note's rule causes the target $DisplayExpression code to be updated. Clever! No fiddling with the Rename dialog.

FWIW, a code note could set more than one target. I think it less likely use, but just to make the point consider this rule:

$DisplayExpression("Task") = $Text;$DisplayExpression("To-do") = $Text;

The code note is now auto-setting the $DisplayExpression of two different unconnected notes. As before, changing the code note's $Text, updates the target notes' $DisplayExpression.
Back to top
 
« Last Edit: Feb 21st, 2013, 5:28am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
How To Fix Actions
Reply #3 - Feb 21st, 2013, 10:29am
 
So, you've written a Tinderbox action. It's big and complex and powerful. And it doesn't work.  

How do you fix it?

0) Make a fresh copy of your document.  We're going to play around; work with that copy.  Take a moment and check that your backups are good.  You do have backups, right?

1) Take the complex action. Copy it. Paste is somewhere else -- into the text of a new note, maybe. Just put it to the side for now. You'll want it later.

2) Extract from that action the very simplest, most trivial core.  Something so simple it couldn't possibly fail.  For example, in the case we've been discussing:

    $Color="bright green"

3) Use that action in the agent, rule, or container you're interested in.  Try it.  Does it do what you expect?  

4) Now, turn back to the complex expression.  Elaborate your action just a tiny bit. Again, you want something simple -- just a little closer to the solution.  For example:

    if($ProportionDone>=1) {
     $Color = "bright green"}

Try that.  Make sure it behaves the way you expect by testing it on a note that has $ProportionDone set to 1.5.  Then try it with $ProportionDone of 0.  All good?

5) Add one more clause.  Test it.

6) Keep adding clauses, testing as you go.

7) Before you know it, you're done.

Tiny steps save time in the end -- especially when things aren't going as they ought.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Setting note color by derived attribute
Reply #4 - Feb 21st, 2013, 12:43pm
 
This page on debugging action code might also help. I've just given it a buff up and included Mark B's useful closing comment (above).
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Rafter T. Sass
Full Member
*
Offline



Posts: 100
Burlington, VT
Re: Setting note color by derived attribute
Reply #5 - Feb 25th, 2013, 11:03pm
 
Thanks so much to both of you for you're helpful and speedy responses! They did the trick.
Back to top
 
 
raughter   IP Logged
Pages: 1
Send Topic Print