Неправильная позиция оси для сгруппированных меток - PullRequest
0 голосов
/ 08 марта 2019

Я бы хотел сгруппировать axes и marks вместе в пределах отметки group, так как мне бы хотелось, чтобы гистограмма была одной из нескольких в данных. Тем не менее, когда я это делаю, ось х переместилась снизу вверх на гистограмму. Вот пример:

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 400,
  "height": 200,
  "padding": 5,
  "data": [
    {
      "name": "cars",
      "format": {
        "type": "json",
        "parse": {
          "year": "date"
        }
      },
      "url": "https://vega.github.io/vega-datasets/data/cars.json",
      "transform": [
        {
          "type": "aggregate",
          "groupby": [
            "Origin"
          ],
          "as": [
            "num_records"
          ]
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "band",
      "domain": {
        "data": "cars",
        "field": "Origin"
      },
      "range": "width",
      "padding": 0.05
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {
        "data": "cars",
        "field": "num_records"
      },
      "range": "height",
      "nice": true
    }
  ],
  "marks": [
    {
      "type": "group",
      "axes": [
        {
          "orient": "bottom",
          "scale": "x"
        },
        {
          "orient": "left",
          "scale": "y"
        }
      ],
      "marks": [
        {
          "type": "rect",
          "from": {
            "data": "cars"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x",
                "field": "Origin"
              },
              "width": {
                "scale": "x",
                "band": 1
              },
              "y": {
                "scale": "y",
                "field": "num_records"
              },
              "y2": {
                "scale": "y",
                "value": 0
              }
            }
          }
        }
      ]
    }
  ]
}

Документация Group Mark предполагает, что группы поддерживают такие вложенные спецификации визуализации. Что я делаю не так?

1 Ответ

0 голосов
/ 13 марта 2019

То, что я делал неправильно, не кодировало ширину и высоту метки группы. Вот мой пересмотренный пример:

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 400,
  "height": 200,
  "padding": 5,
  "data": [
    {
      "name": "cars",
      "format": {
        "type": "json",
        "parse": {
          "year": "date"
        }
      },
      "url": "https://vega.github.io/vega-datasets/data/cars.json",
      "transform": [
        {
          "type": "aggregate",
          "groupby": [
            "Origin"
          ],
          "as": [
            "num_records"
          ]
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "band",
      "domain": {
        "data": "cars",
        "field": "Origin"
      },
      "range": "width",
      "padding": 0.05
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {
        "data": "cars",
        "field": "num_records"
      },
      "range": "height",
      "nice": true
    }
  ],
  "marks": [
    {
      "type": "group",
      "axes": [
        {
          "orient": "bottom",
          "scale": "x"
        },
        {
          "orient": "left",
          "scale": "y"
        }
      ],
      "encode": {
        "enter": {
          "width": {
            "signal": "width"
          },
          "height": {
            "signal": "height"
          }
        }
      },
      "marks": [
        {
          "type": "rect",
          "from": {
            "data": "cars"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x",
                "field": "Origin"
              },
              "width": {
                "scale": "x",
                "band": 1
              },
              "y": {
                "scale": "y",
                "field": "num_records"
              },
              "y2": {
                "scale": "y",
                "value": 0
              }
            }
          }
        }
      ]
    }
  ]
}
...