在Mathematica中处理自定义表格表示

时间:2011-06-13 16:56:52

标签: dynamic wolfram-mathematica tabular

考虑以下数据示例:

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

以下函数生成自定义表格表示:

(您可以参考Mr.Wizard extensive solution for customizable tabular representations。  最后,我也会操纵他提供的选项,现在)

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]}
    ];

我想使用Manipulate或Dynamic来显示我的数据的部分内容。 这将选择我想要显示的列范围,要显示的行数以及颜色。

以下是我未完成的尝试。

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

我如何使用setter更新颜色值?

是否可以在Manipulate窗口中实际拥有它?

欢迎任何其他建议使这种高效的外观。

- 编辑:由于下面的Belisarius解决方案,我现在可以做什么:

enter image description here

1 个答案:

答案 0 :(得分:2)

尝试类似:

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