在hconcat合成中格式化文本标记。

huangapple go评论59阅读模式
英文:

formatting text marks in a hconcat composition

问题

我有这个要点:我的示例表

我有两个问题:

  • 我能单独控制第二个 "sumofvals" 和第三个 "the individuals" 视图之间的间距吗?我想让它们更靠近。
  • 我能将颜色扩展到 "header" 吗?

Tom

英文:

I have this gist: my sample table

I have two questions:

  • Can I control the spacing between the 2nd "sumofvals" and the 3rd "the individuals" view control separately, I want them closer together
  • Can I extend the coloring to the "header" as well

Tom

答案1

得分: 2

以下是您提供的内容的中文翻译:

您可以统一控制间距,但无法单独控制。但是,您可以添加一些虚拟视图来进行以下操作。

至于背景颜色,这些是坐标轴标签,我过去的做法是在正确的轴位置叠加标记。再次强调,这都是一种非常巧妙的方法,最好使用Vega。

在hconcat合成中格式化文本标记。

{
  "data": {
    "values": [
      {
        "rowh": "亚洲",
        "rowgroup": "I",
        "vals": 2000000,
        "val": 3000000,
        "valt": 11000000
      },
      {
        "rowh": "亚洲",
        "rowgroup": "II",
        "vals": 2000000,
        "val": 8000000,
        "valt": 11000000
      },
      {
        "rowh": "欧洲",
        "rowgroup": "I",
        "vals": 2000000,
        "val": 3000000,
        "valt": 6000000
      },
      {
        "rowh": "欧洲",
        "rowgroup": "II",
        "vals": 2000000,
        "valt": 1000000,
        "val": 6000000
      },
      {
        "rowh": "美国",
        "rowgroup": "I",
        "vals": 2000000,
        "val": 2000000,
        "valt": 7000000
      },
      {
        "rowh": "美国",
        "rowgroup": "II",
        "vals": 2000000,
        "val": 3000000,
        "valt": 7000000
      }
    ]
  },
  "transform": [
    {
      "joinaggregate": [{"field": "val", "op": "sum", "as": "rowgroupsum"}],
      "groupby": ["rowh"]
    },
    {"calculate": "'开始'", "as": "labels"},
    {"calculate": "'结束'", "as": "labele"},
    {"calculate": "'sumofvals'", "as": "labelvalsum"},
    {"calculate": "datum['vals']+datum['rowgroupsum']", "as": "labelse"}
  ],
  "config": {"concat": {"spacing": 0}},
  "hconcat": [
    {
      "width": 50,
      "mark": {"type": "text", "align": "center"},
      "encoding": {
        "y": {"field": "rowh", "type": "nominal"},
        "x": {
          "field": "labels",
          "type": "nominal",
          "axis": {"title": null, "orient": "top", "labelAngle": 0}
        },
        "text": {"field": "vals", "type": "quantitative", "format": "0.1s"}
      }
    },
    {"width": 30, "mark": {"type": "text"}},
    {
      "width": 50,
      "view": {"fill": "steelblue", "stroke": "black"},
      "layer": [
        {"mark": {"type": "bar"}, "encoding": {"y": {"value": -20}}},
        {
          "mark": {"type": "text"},
          "encoding": {"y": {"value": -10}, "text": {"value": "sumofvals"}}
        },
        {
          "mark": {"type": "text", "align": "center"},
          "encoding": {
            "y": {"field": "rowh", "type": "nominal", "axis": null},
            "x": {
              "field": "labelvalsum",
              "type": "nominal",
              "axis": {"title": null, "orient": "top", "labelAngle": 0}
            },
            "text": {
              "field": "rowgroupsum",
              "type": "quantitative",
              "format": "0.1s"
            }
          }
        }
      ]
    },
    {
      "width": 50,
      "view": {"fill": "lightgrey"},
      "mark": {"type": "text", "align": "center"},
      "encoding": {
        "y": {"field": "rowh", "type": "nominal", "axis": null},
        "x": {
          "field": "rowgroup",
          "type": "nominal",
          "axis": {"title": null, "orient": "top", "labelAngle": 0}
        },
        "text": {"field": "val", "type": "quantitative", "format": "0.1s"}
      }
    },
    {"width": 30, "mark": {"type": "text"}},
    {
      "width": 50,
      "view": {"fill": "orange"},
      "mark": {"type": "text", "align": "center"},
      "encoding": {
        "y": {"field": "rowh", "type": "nominal", "axis": null},
        "x": {
          "field": "labele",
          "type": "nominal",
          "axis": {"title": null, "orient": "top", "labelAngle": 0}
        },
        "text": {"field": "labelse", "type": "quantitative", "format": "0.2s"}
      }
    }
  ]
}
英文:

You can uniformly control spacing but not individually. However, you can add in some fake views to hack it as follows.

As for the background colours, these are axis labels and the way I have done this in the past is to overlay marks at the right axis position. Again this is all very hacky and you're probably best using Vega.

在hconcat合成中格式化文本标记。

{
"data": {
"values": [
{
"rowh": "Asia",
"rowgroup": "I",
"vals": 2000000,
"val": 3000000,
"valt": 11000000
},
{
"rowh": "Asia",
"rowgroup": "II",
"vals": 2000000,
"val": 8000000,
"valt": 11000000
},
{
"rowh": "Europe",
"rowgroup": "I",
"vals": 2000000,
"val": 3000000,
"valt": 6000000
},
{
"rowh": "Europe",
"rowgroup": "II",
"vals": 2000000,
"valt": 1000000,
"val": 6000000
},
{
"rowh": "US",
"rowgroup": "I",
"vals": 2000000,
"val": 2000000,
"valt": 7000000
},
{
"rowh": "US",
"rowgroup": "II",
"vals": 2000000,
"val": 3000000,
"valt": 7000000
}
]
},
"transform": [
{
"joinaggregate": [{"field": "val", "op": "sum", "as": "rowgroupsum"}],
"groupby": ["rowh"]
},
{"calculate": "'Start'", "as": "labels"},
{"calculate": "'End'", "as": "labele"},
{"calculate": "'sumofvals'", "as": "labelvalsum"},
{"calculate": "datum['vals']+datum['rowgroupsum']", "as": "labelse"}
],
"config": {"concat": {"spacing": 0}},
"hconcat": [
{
"width": 50,
"mark": {"type": "text", "align": "center"},
"encoding": {
"y": {"field": "rowh", "type": "nominal"},
"x": {
"field": "labels",
"type": "nominal",
"axis": {"title": null, "orient": "top", "labelAngle": 0}
},
"text": {"field": "vals", "type": "quantitative", "format": "0.1s"}
}
},
{"width": 30, "mark": {"type": "text"}},
{
"width": 50,
"view": {"fill": "steelblue", "stroke": "black"},
"layer": [
{"mark": {"type": "bar"}, "encoding": {"y": {"value": -20}}},
{
"mark": {"type": "text"},
"encoding": {"y": {"value": -10}, "text": {"value": "sumofvals"}}
},
{
"mark": {"type": "text", "align": "center"},
"encoding": {
"y": {"field": "rowh", "type": "nominal", "axis": null},
"x": {
"field": "labelvalsum",
"type": "nominal",
"axis": {"title": null, "orient": "top", "labelAngle": 0}
},
"text": {
"field": "rowgroupsum",
"type": "quantitative",
"format": "0.1s"
}
}
}
]
},
{
"width": 50,
"view": {"fill": "lightgrey"},
"mark": {"type": "text", "align": "center"},
"encoding": {
"y": {"field": "rowh", "type": "nominal", "axis": null},
"x": {
"field": "rowgroup",
"type": "nominal",
"axis": {"title": null, "orient": "top", "labelAngle": 0}
},
"text": {"field": "val", "type": "quantitative", "format": "0.1s"}
}
},
{"width": 30, "mark": {"type": "text"}},
{
"width": 50,
"view": {"fill": "orange"},
"mark": {"type": "text", "align": "center"},
"encoding": {
"y": {"field": "rowh", "type": "nominal", "axis": null},
"x": {
"field": "labele",
"type": "nominal",
"axis": {"title": null, "orient": "top", "labelAngle": 0}
},
"text": {"field": "labelse", "type": "quantitative", "format": "0.2s"}
}
}
]
}

答案2

得分: 2

这有点取巧,但试试这样做...

在你的hconcat上方添加一个spacing设置:

"spacing": 0,
"hconcat": [

然后在想要实际空格的地方添加一些新的虚拟层。例如,在连接1和3之后:

{"width": 20, "mark": {"type": "text", "align": "center"}},

当你说标题时,你是指X轴标签吗?

对于标签颜色,你只需在labelAngle之后添加X轴的代码。

对每个hconcat元素都这样做,并将颜色更改为灰色、钢蓝等:

"labelAngle": 0, "labelColor": "orange"
英文:

Its a bit of a hack but try this..

Above your hconcat add a spacing setting:

"spacing": 0,
"hconcat": [

Then add some new dummy layers where you want your actual spaces. For example after concat 1 and 3:

{"width": 20, "mark": {"type": "text", "align": "center"}},

When you say Header do you mean your X axis labels?

For your label colors you can just add in your X axis axis code after the labelAngle.

Do this for each hconcat element and change the color to grey, steelblue etc

"labelAngle": 0, "labelColor": "orange"

Adam

huangapple
  • 本文由 发表于 2023年5月26日 14:17:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定