2

Considering the following data example :

data ={
       {"a", "b", "c", "d", "e"},
       {1, 2, 3, 4, 5},
       {11, 12, 13, 14, 15}, 
       {21, 22, 23, 24, 25}
      };

And the following Function to generate customized Tabular representation :

(and you can refer to Mr.Wizard extensive solution for customizable tabular representations. Ultimatly I would also manipulate the options he offered, for now )

DataSampleX[data_, linesNumber_, range1_, range2_, color1_, color2_, color3_] :=

Grid[
 Join[
      {Range[range1, range2]}, {Map[Rotate[Text[#], 90 Degree] &,
       data[[1, range1 ;; range2]]]}, 
       data[[2 ;; linesNumber, range1 ;; range2]]
     ],
       Background    -> {{{{color1, color2}}, {1 -> color3}}},
       Dividers      -> {All, {1 -> True, 2 -> True, 3 -> True,0 -> True}},
       ItemSize      -> {1 -> Automatic, Automatic},
       Alignment     -> Top,
       Frame         -> True,
       FrameStyle    -> Thickness[2],
       ItemStyle     -> {Automatic, Automatic, 
                        {{1, 1}, {1, Length[data]}} ->Directive[FontSize -> 
                        15, Black, Bold]}
    ];

I would like to use Manipulate or Dynamic to display parts of my data using the above. This choosing the range of column I want to display, the number of lines to display as well as colors.

Below is my unfinished attempt.

PopupMenu[Dynamic[range1], Range[1, Length@data[[1]] - 1, 1]]
PopupMenu[Dynamic[range2], Range[2, Length@data[[1]], 1]]
PopupMenu[Dynamic[linesNumber], Range[2, Length@data[[All, 1]] - 1, 1]]
Dynamic[DataSampleX[data, linesNumber, range1, range2, LightBlue, 
LightGray, LightYellow]]

enter image description here

enter image description here

How could I use setter to update the Color Value ?

Is it possible to actually have this in a Manipulate window ?

Any other suggestion to make this efficient look good is welcome.

-EDIT : What I am able to do now thanks to Belisarius solution below :

enter image description here

Community
  • 1
  • 1
500
  • 6,509
  • 8
  • 46
  • 80

1 Answers1

2

Try something like:

colsel = (#->Graphics[{#, Disk[]},ImageSize -> 15])& /@ColorData[1, "ColorList"];
s[x_] := Style[x, Black, Bold, 12];
ct = ControlType -> PopupMenu;

Manipulate[
 DataSampleX[data, linesNumber, range1, range2, color1, color2, color3],
 Row[{
   Column[{
    Control@{{range1,      1, s@"Range1"}, Range[1, Length@data[[1]] - 1],  ct}, 
    Control@{{range2,      2, s@"Range2"}, Range[2, Length@data[[1]] - 1],  ct}, 
    Control@{{linesNumber, 2, s@"Lines"},  Range[2,Length@data[[All, 1]]-1],ct}}],
   Spacer[20],
   Column[{
     Control@{{color1, colsel[[1, 1]], s@"Color 1"}, colsel, ct}, 
     Control@{{color2, colsel[[2, 1]], s@"Color 2"}, colsel, ct}, 
     Control@{{color3, colsel[[3, 1]], s@"Color 3"}, colsel, ct}}]
 }]]

enter image description here

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • @500 Don't you love those little tricks with Mma such as showing a colored disk where you were supposed to put some text? – Dr. belisarius Jun 13 '11 at 18:31
  • @Belisarius, how would you prevent range1 > range2 in the Control ? – 500 Jun 13 '11 at 18:33
  • 1
    @500 try using Range[1,range2] in the range1 limits spec – Dr. belisarius Jun 13 '11 at 18:46
  • @Belisarius, given how fast and elegantly did you solve & extended my problem, I have a dream : Could all the column headers become setter button you click on to add it to the display. Instead of setting a range, one would click on all the names of the columns he wish to display. Is it something doable ? I would post a new question would it be ! – 500 Jun 13 '11 at 18:47
  • @500 You mean as a `SetterBar`? – Dr. belisarius Jun 13 '11 at 18:53
  • @Belisarius, Yes ! I believe you are missing ]] at the end of your code. Also I have unsuccessfully tried to change "ColorList" to "TemperatureMap" for example. How would you do it ? – 500 Jun 13 '11 at 18:59
  • @500 yep. It was a copy/paste error. ColorList is discrete and finite, while most other color maps are continuous, so it is easier with ColorList ... it was not an accident :) – Dr. belisarius Jun 13 '11 at 19:03
  • @Belisarius, I shall then try to create my own discrete ColorList ! Any other discrete ready made you know about ? And thank you again, this tool is precious to me ! – 500 Jun 13 '11 at 19:15
  • @500 Run Grid[Partition[ Framed[Show[ColorData[#, "Image"], ImageSize -> 100], FrameStyle -> Gray] & /@ ColorData["Indexed"], 4, 4, 1, {}], Spacings -> .25] – Dr. belisarius Jun 13 '11 at 20:19
  • @Belisarius, Amazing ! How could I read there name to implement it in your code ? – 500 Jun 13 '11 at 20:29
  • 1
    @500 Those are the "Indexed" Colormaps. ColorData[1], ... ColorData[62] ... no need to use a "name" – Dr. belisarius Jun 13 '11 at 20:32