2011-06-16 95 views
4

建立在Belisarius在"Manipulate custom Tabular"提出的解決方案上。在Mathematica動態列表中選擇另一個動態

  • 考慮下面的函數來創建自定義表格表示:

    DataSampleXX[data_, linesNumber_, columnsList_, color1_, color2_, color3_] := 
    
    Grid[ 
    Join[ 
        {columnsList}, {Map[Rotate[Text[#], 90 Degree] &, 
         data[[1, columnsList]]]}, data[[2 ;; linesNumber, columnsList]]], 
    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]} 
    ]; 
    
  • ,後面的數據:

    soData = {{"col1", "col2", "col3", "col4", "col5", "col6", "col7", 
          "col8", "col9", "col10"}, Range[1, 10], Range[11, 20], 
          Range[21, 30], Range[31, 40]} 
    
    
    With[ 
        {columnsList = {1, 3}, 
         data = soData, 
         linesNumber = 3, 
         color1 = LightBlue, 
         color2 = LightRed, 
         color3 = LightGray}, 
         DataSampleXX[data, linesNumber, columnsList, color1, color2, color3]] 
    

Output

  • 我想集成下面的Dynamic來提供DataSampleXX函數的columnsList參數。

    Manipulate[[email protected][Sequence @@ {a, b}], 
          Evaluate[Sequence @@ MapThread[{{#1, {}, ""}, #2, 
          ControlType -> TogglerBar} &, {{a, b}, 
          Partition[Rule @@@ Transpose[{Range[10], soData[[1]]}], 5]}]], 
          ControlPlacement -> Top] 
    

What I want

  • 這將使我動態選擇列(VS一系列在我剛纔的問題列)使用DataSampleXX顯示,但我又不能老是圖瞭解如何合併這兩種機制。

回答

7

你想做什麼需要一些技巧。

例如:

Maipulate[ f[ Array[ a, exp], ...], ...] 

和類似的構建體不工作(並且在文檔被解釋),因爲a[_]不在表達顯式的,從而使得它有一個可變數目的控制困難。我找到了解決辦法是:

Manipulate[ f[#,...], ... ] & @ Array[a, exp] 

另一個問題是構建

[email protected](.#.) &/@ _controls_ 

不允許本身二維分區,所以我們必須使用這兩種控制@語法選項(控制@和{...}),這是沒有記錄。

其他令人討厭的東西你可以在下面的代碼中找到。

所以:

soData = {{"col01", "col02", "col03", "col04", "col05", "col06", 
      "col07", "col08", "col09", "col10"}, 
      Range[1, 10], Range[11, 20], Range[21, 30], Range[31, 40]}; 
perRow = 5; 
colsel = (# -> Graphics[{#, Disk[]}, ImageSize -> 15]) &/@ColorData[1, "ColorList"]; 
s[x_] := Style[x, Black, Bold, 12]; 
ct = ControlType -> PopupMenu; 

Manipulate[ 
    DataSampleXX[soData, linesNumber, [email protected][Sequence @@ #], color1, 
                   color2, color3], 
    Row[ 
    {Column[ 
     {[email protected]{{linesNumber, 2, [email protected]"Lines"}, 
     Range[2, [email protected][[All, 1]] - 1], ct}}], 
     Spacer[20], 
    Column[ 
     {[email protected]{{color1, colsel[[1, 1]], [email protected]"Color 1"}, colsel, ct}, 
     [email protected]{{color2, colsel[[2, 1]], [email protected]"Color 2"}, colsel, ct}, 
     [email protected]{{color3, colsel[[3, 1]], [email protected]"Color 3"}, colsel, ct}}]}], 
    Evaluate[ 
    Sequence @@ 
    MapThread[{{#1, {}, ""}, #2, ControlType -> TogglerBar} &, 
     {#, Partition[Rule @@@ Transpose[{Range[10], soData[[1]]}], perRow]}]]] &@ 
Array[a, Length[soData[[1]]]/perRow] 

enter image description here

+0

@Belisarius,它是!現在,我的問題是,我有100列,這就是爲什麼我分成五組,有沒有辦法調整你的代碼這樣做呢?另外,我曾經試着根據你提供的地址向你發送一封電子郵件在你的個人資料上沒有成功我想告訴你我使用某些解決方案的方式! – 500 2011-06-16 17:10:15

+0

@ 500讓我看看我能不能找出一百個問題的答案。重新「我的電子郵件」......它正在工作。聽起來很愚蠢,但是......你用相應的符號代替了「[點]」和「[at]」嗎? – 2011-06-16 17:31:32

+0

@Belisarius,剛剛發給你一封電子郵件,以防它進入你的垃圾郵件箱。我希望我的代碼不會讓你的專家眼光難看。非常感謝您的關注。 – 500 2011-06-16 19:41:15