Adding Mechanisms to Color Cells in TablePlugin.
Description
This is an extension to
TablePlugin (see
TablePluginDev) to allow users to to do more.
The initial motivation was the ability to color a row by the
value of one of its columns (for example, bugs color-coded by owner, or priority, etc). That was a relatively simple change, so I thought of other coloring schemes. Implementing these made the code
TablePlugin.pm quite ugly so I built an extension package which actually does the work of figuring out a cell's color and hands that value back to
TablePlugin.pm.
The diff to
TablePlugin is a dozen lines (everything else is in the extension package) - all of it to set-up the hook and process additional TABLE attributes and preferences.
Is this of interest to the general community/TablePlugin writer?
Examples
Here are some examples (direct form the output, table data is omitted from code but is just as in the | X | syntax):
(assembling)....
Rows colored by color set
Just like
TablePlugin (default)...
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFffA5,#ffeeee"
cellcoloring="horizontal"}%
| this | that | those | these |
| when | did | fireflies | become |
| enslaved | into | cellphone | buttons? |
| why | is | our | calendar |
| so | enmeshed | in | fragments? |
| have | you | ever | washed a |
| baby | in | a | watermelon? |
Columns colored by color set
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFffA5,#ffeeee" cellcoloring="vertical"}%
| this | that | those | these |
| when | did | fireflies | become |
| enslaved | into | cellphone | buttons? |
| why | is | our | calendar |
| so | enmeshed | in | fragments? |
| have | you | ever | washed a |
| baby | in | a | watermelon? |
Alternates on the diagonal - two colors becomes chessboard (useless?)
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFffA5,#ffeeee" cellcoloring="diagonal"}%
| this | that | those | these |
| when | did | fireflies | become |
| enslaved | into | cellphone | buttons? |
| why | is | our | calendar |
| so | enmeshed | in | fragments? |
| have | you | ever | washed a |
| baby | in | a | watermelon? |
Color code cell by cell value
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFffA5,#DFA5ff,#ffeeee"
cellcoloring="filter" bgfilter="Yes,No"}%
| Who | Dishes | Lawn | Laundry |
| Maggie | Yes | No | -- |
| Cynthia | No | Yes | Yes |
| Mommy | No | No | Yes |
| Johnny | -- | Yes | Yes |
| Papa | Yes | Yes | Yes |
Color code rows by column value
%TABLE{tableborder="0" cellpadding="3" cellspacing="1" headerbg="#AACCCC" databg="#DFA5ff,#ffDFA5,#A5ffD5,#ffeeee" cellcoloring="filterbycol:2" bgfilter="Cynthia,Johnny,Maggie"}%
| Chore | Owner | Priority | Comment |
| garbage | Mommy | --- | DNA experiment! |
| lawn | Cynthia | medium | "English garden"! |
| bills | Mommy | --- | Knock! Knock! |
| laundry | Maggie | medium | Not a nudist camp! |
| garage | Papa | --- | Sale! |
| dishes | Johnny | high | No forks! |
| vacuum | Maggie | low | Asthmosis! |
Highlight a row, a column or both
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFA5ff,#ffDFA5,#ffeeee"
cellcoloring="highlight:4:3"}%
| Name | Gender | Disposition | Comment |
| Mommy | F | chummy | Don't use my real name! |
| Cynthia | F | naughty | GTK, Ru2? |
| Papa | M | fickle | too much time |
| Maggie | F | slinky | mumblemumble |
| Johnny | M | lazy | GameBoy? (tm) |
Silly #1
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFA5ff,#ffDFA5,#ffeeee"
cellcoloring="gradientdia"}%
This example changes the color gradiently on the diagnal (not really useful, but easy to implement).
| this | that | those | these |
| when | did | fireflies | become |
| enslaved | into | cellphone | buttons? |
| why | is | our | calendar |
| so | enmeshed | in | fragments? |
| have | you | ever | washed a |
| baby | in | a | watermelon? |
Silly #2
%TABLE{tableborder="0" cellpadding="3" cellspacing="1"
headerbg="#AACCCC" databg="#DFA5ff,#ffDFA5,#A5ffDF,#ffeeee"
cellcoloring="filtermix" bgfilter="wa,en,me"}%
This example highlights cells depending on whether they have particular substrings (in this case wa, en, me; with the colors #ffDFA5,#A5ffDF,#ffeeee, mixing the colors where more than one substring occurs).
| this | that | those | these |
| when | did | fireflies | become |
| enslaved | into | cellphone | buttons? |
| why | is | our | calendar |
| so | enmeshed | in | fragments? |
| have | you | ever | washed a |
| baby | in | a | watermelon? |
Implementations
If this is useful to folks, I can document more, implement CGI parameterization and put it all neatly together....
--
SlavaKozlov - 12 Feb 2002
I added an alpha version below. the diff to the
TablePlugin, the extension, and some usage sample files.
--
SlavaKozlov - 13 Feb 2002
Was there any work to officially integrate this into
TablePlugin???
--
JohnCavanaugh - 14 Mar 2003
I don't believe there was any attempt to officially integrate it into thw TWiki. It should relatively easy as much of the work is done outside of the
TablePlugin code itself.
--
SlavaKozlov - 21 Aug 2003
The coloring extensions look neat but are too esoteric for general use, there could also be a performance impact. For those who want these extensions: A possible solution is to add a hook into the
TablePlugin, e.g. the coloring extensions would be an add-on to the
TablePlugin.
--
PeterThoeny - 22 Aug 2003
I like the cell coloring by filter. It could be useful in some of our uses of tables. Like highlighting action items which are
open, etc.
I really don't like having to patch either the core or other plugins to get a plugin to work. Either package all of this up into a new
ColoringTablePlugin or follow Peter's suggestion of enhancing the
TablePlugin to allow extensions to it. The later is more flexible, but the former is probably faster and easier to implement.
I do like some of these capabilities. Thanks!
--
MartyBacke - 22 Aug 2003
I was looking here because I need also some kind of user driven extension of coloring table cells. With 3 lines of code added to the
TablePlugin I can define
%TABLE{ databg="none" tableborder="0" cellspacing="3" cellpadding="3" valign="top"}%
| %CLASS{onecolor}% Zeile 1 | weiterer Text%BR%zweite Zeile |
| %CLASS{anothercolor}% Zeile 2 | weiterer Text |
| %CLASS{onecolor}% Zeile 3 | asdfffff |
| Zeile 1 |
weiterer Text zweite Zeile |
| Zeile 2 |
weiterer Text |
| Zeile 3 |
asdfffff |
...
$cell = "$color $cell ";
$cell .= "" if( $color );
}
# added code
if ( $cell =~ s/(.*)%CLASS{(.*)}%// ) {
$attr .= " class=\"$2\"";
}
# end added code
$text .= "<$type$attr>$cell";
$text .= "$type>";
$colCount++;
}
We need such more functional attributes defined better in style sheets than in hardcoded colors.
I'm not shure if tis is the right way %CLASS{...}% is not used as a real wiki macro.
Is it possible to add such a feature to
TablePlugin in this or another way. I hate it to patch own extensions after upgrades.
--
GuentherFischer - 13 Oct 2003
Is there a Plugin API for allowing one plugin to add handlers that other plugins could then use to carry out extension functions?
--
JadeCravy - 17 Jun 2006
There is no standard yet to extend Plugins by other Plugins. Please feel free to create a brainstorming topic in the
Codev web.
--
PeterThoeny - 27 Jun 2006
Hm, couldn't this be done if the
TablePlugin would be based on a kind of
TableContrib that provides the basic features, thus making it possible to write an
EnhancedTablePlugin without loosing backwards compatibility. Just a thought.
--
FranzJosefSilli - 28 Jun 2006
That is an option, yes. Another option is to enhance the
TablePlugin with a callback feature where other Plugins can do additional manipulation. The other Plugin calls an install handler of the TablePlugin, the TablePlugin calls this handler when tables are rendered.
A clean solution is to enhance TWiki with an object oriented Plugins API where Plugins can override methods of other Plugins, and call the method of the super class if needed.
--
PeterThoeny - 28 Jun 2006