Mathematica 中另一个 Dynamic 中的动态列表选择

发布于 2024-11-16 06:49:31 字数 1565 浏览 4 评论 0原文

以贝利撒留在“操作自定义表格”中提出的解决方案为基础。

  • 考虑以下函数来创建自定义表格表示:

    DataSampleXX[数据_、行数_、列列表_、颜色 1_、颜色 2_、颜色 3_] :=
    
    网格[
    加入[
         {columnsList}, {地图[旋转[文本[#], 90 度] &, 
          数据[[1,列列表]]]},数据[[2 ;;行数,列列表]]],
    背景-> {{{{颜色1,颜色2}},{1 ->颜色3}}},
    分隔线 -> {全部,{1 ->正确,2 ->正确,3 ->正确,0 ->真的}},
    项目尺寸 -> {1->自动,自动},
    对齐->顶部,
    框架->真的,
    框架样式->厚度[2],
    项目样式 -> {自动的, 
    自动,{{1, 1}, 
    {1,长度[数据]}} ->指令[字体大小 -> 15、黑色、粗体]}
    ];
    
  • 以及以下数据:

    soData = {{"col1", "col2", "col3", "col4", "col5", "col6", "col7", 
               "col8", "col9", "col10"}, 范围[1, 10], 范围[11, 20], 
                范围[21, 30], 范围[31, 40]}
    
    
    和[
         {列列表 = {1, 3},
          数据=所以数据,
          行数 = 3,
          颜色1 = 浅蓝色,
          颜色2 = 浅红色,
          color3 = 浅灰色},
          DataSampleXX[数据,行数,列列表,颜色1,颜色2,颜色3]]
    

Output

  • 我想将以下动态集成到提供 DataSampleXX 函数的 columnsList 参数。

    Manipulate[Sort@Join[Sequence @@ {a, b}], 
               评估[序列@@ MapThread[{{#1, {}, ""}, #2, 
               控制类型-> TogglerBar} &, {{a, b},
               分区[规则@@@转置[{范围[10], soData[[1]]}], 5]}]], 
               控制放置 ->顶部]
    

我想要什么

  • 这应该使我能够动态选择列(VS 中的一系列列)我之前的问题)使用 DataSampleXX 显示,但我还不知道如何合并这两种机制。

Building up on the solution proposed by Belisarius in "Manipulate custom Tabular".

  • Consider the following Function to create custom Tabular representation :

    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]}
    ];
    
  • And the following data :

    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

  • I would like to integrate the following Dynamic to feed the columnsList argument of the DataSampleXX Function.

    Manipulate[Sort@Join[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

  • This should enable me to dynamically choose the columns (VS a range of column in my previous question) to display using DataSampleXX but I yet can`t figure out how to merge the 2 mechanisms.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿光 2024-11-23 06:49:31

你想做的事情需要一些技巧。

例如:

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

和 类似的构造不起作用(并在文档中进行了解释),因为 a[_] 在表达式中不明确,因此很难拥有可变数量的控件。我发现的解决方案是:

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

另一个问题是该构造

 Control@( .#. ) &/@ _controls_ 

本身不允许二维分区,因此我们必须使用两个 Control@ 语法选项( Control@ 和 { ... }),这没有记录。

您可以在下面的代码中找到其他麻烦。

所以:

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, Sort@Join[Sequence @@ #], color1,
                                                               color2, color3], 
   Row[
     {Column[
       {Control@{{linesNumber, 2, s@"Lines"}, 
         Range[2, Length@soData[[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}}]}], 
   Evaluate[
    Sequence @@ 
     MapThread[{{#1, {}, ""}, #2, ControlType -> TogglerBar} &, 
        {#, Partition[Rule @@@ Transpose[{Range[10], soData[[1]]}], perRow]}]]] &@ 
Array[a, Length[soData[[1]]]/perRow]

在此处输入图像描述

What you want to do needs a few tricks.

For example:

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

and similar constructs do not work (and is explained in the docs), because the a[_] are not explicit in the expression, so making it difficult to have a variable number of controls. The solution I found is:

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

Other problem is that the construct

 Control@( .#. ) &/@ _controls_ 

does not allow per se a two dimensional partition, so we have to use both Control@ syntax options ( Control@ and { ... }), which is not documented.

Other nuisances you can find in the code below.

So:

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, Sort@Join[Sequence @@ #], color1,
                                                               color2, color3], 
   Row[
     {Column[
       {Control@{{linesNumber, 2, s@"Lines"}, 
         Range[2, Length@soData[[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}}]}], 
   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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文