question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It would be useful to have a transform that “rotates” the data, so you could send column oriented data like:

{"a": [1, 2, 3], "b": [4, 5, 6]}

and have it converted to:

[{"a": 1, "b": 4}, {"a":2, "b": 5}, {"a": 3, "b": 6}]

this would reduce the size of the vega spec (esp. datasets with many rows) and would be much easier (and faster) to generate from R.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcpruxcommented, Apr 1, 2019

The way I reduce the size of the data (at the cost of some readability) is to just use bare arrays for the data rows and reference them by index. For example, instead of https://vega.github.io/editor/#/examples/vega/bar-chart :

  "data": [
    {
      "name": "table",
      "values": [
        {"category": "A", "amount": 28},
        {"category": "B", "amount": 55},
        {"category": "C", "amount": 43},
        {"category": "D", "amount": 91},
        {"category": "E", "amount": 81},
        {"category": "F", "amount": 53},
        {"category": "G", "amount": 19},
        {"category": "H", "amount": 87}
      ]
    }
  ],
  …
  "scales": [
    {
      "name": "xscale",
      "type": "band",
      "domain": {"data": "table", "field": "category"},
      "range": "width",
      "padding": 0.05,
      "round": true
    },
    {
      "name": "yscale",
      "domain": {"data": "table", "field": "amount"},
      "nice": true,
      "range": "height"
    }
  ],

you can define the data as an array-of-arrays and just reference the field by index (which seems to work, despite not being listed as a valid field format at https://vega.github.io/vega/docs/types/#Field):

  "data": [
    {
      "name": "table",
      "values": [
        ["A", 28],
        ["B", 55],
        ["C", 43],
        ["D", 91],
        ["E", 81],
        ["F", 53],
        ["G", 19],
        ["H", 87]
      ]
    }
  ],
  …
  "scales": [
    {
      "name": "xscale",
      "type": "band",
      "domain": {"data": "table", "field": "0"},
      "range": "width",
      "padding": 0.05,
      "round": true
    },
    {
      "name": "yscale",
      "domain": {"data": "table", "field": "1"},
      "nice": true,
      "range": "height"
    }
  ]

Another possibility is to try the new Apache Arrow loader and store your data in the arrow format: https://github.com/vega/vega-loader-arrow

0reactions
domoritzcommented, Apr 1, 2019

I’m closing this issue since flatten does what you ask for. Let us know if there is anything else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rotate() - CSS: Cascading Style Sheets - MDN Web Docs
The rotate() CSS function defines a transformation that rotates an element around a fixed point on the 2D plane, without deforming it.
Read more >
CSS transform property - W3Schools
The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements....
Read more >
Scripting API: Transform.Rotate - Unity - Manual
Use Transform.Rotate to rotate GameObjects in a variety of ways. The rotation is often provided as an Euler angle and not a Quaternion....
Read more >
rotate | CSS-Tricks
The rotate property in CSS turns an element around one or more axes. ... …the CSS rotate property does it independently of the...
Read more >
RotateTransform Class (System.Windows.Media)
When you use a RotateTransform, realize that the transformation rotates the coordinate system for a particular object about the point (0, 0).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found