A visualization in DXR is a collection of graphical marks (Unity game objects) whose visual channels or properties (position, color, size, etc.) can be mapped to data attributes. As the designer, you can specify this mapping using a high-level visualization grammar inspired by Vega-Lite, documented in the Grammar Docs. At its core, DXR takes your data and a vis specification or vis specs as input and generates an immersive visualization as output. As illustrated in the example below, given the data as a JSON file (left) and a vis specification as a JSON file (middle), DXR generates a visualization (right) within a Unity scene.
input: data
input: vis specification (vis specs)
output: immersive visualization
For each data item in the data, DXR generates an instance of the graphical mark (e.g., cube game object), and modifies its visual channels/properties (e.g., x, y positions) according to the values of data attributes (e.g., Horsepower, Miles_per_Gallon) as described in the vis specs, resulting in a visualization as shown above. This is the main recipe in DXR: data + vis specs = visualization.
Now that you know the recipe, let's set up your development environment, and then create your first immersive visualization!
1. Create an instance of the DXRVis prefab in your scene. The DXRVis prefab is the template for an immersive visualization in DXR. Drag-and-drop the DXRVis prefab (found under Assets/DxR/Prefabs) into the Hierarchy window. You should now have a DXRVis game object instanced in your scene.
2. Adjust the DXRVis transform as needed. For example, to place the visualization in front of the user, 2 meters away, set the position to 0, 0, 2. Note that Unity follows the convention: 1 spatial unit is equivalent to 1 meter in XR.
3. Next, we need to specify which JSON file to use as the vis specs: click on the DXRVis game object and set/edit the “Vis Specs URL” attribute in the Inspector window. Note that this filename is relative to the Assets/StreamingAssets/DxRSpecs/ directory. For this example, let's create the empty file Assets/StreamingAssets/DxRSpecs/scatterplot.json.
4. Now it's time to specify our visualization design by modifying the vis specs using your favorite text/code editor (e.g., Visual Studio, Atom). Copy-then-paste the specification from the example above (middle) into scatterplot.json, then save. Looking at the vis specs, intuitively, we can tell that the data
keyword corresponds to the data source, the mark
specifies the graphical mark, and x, y
, are the visual (spatial position) channels on which the quantitative
data attributes Horsepower
and Miles_per_Gallon
are mapped to, respectively. Note that the data url
is relative to Assets/StreamingAssets/DxRData/, e.g., a data url of cars.json
should be in Assets/StreamingAssets/DxRData/cars.json.
5. Press play! You should now see a 2D scatterplot in front of you in XR like above (right). You can "tap" the anchor (red-box) near the origin to "drag-and-drop" the visualization in your XR space.
One of the ways to edit your visualization is via the graphical user interface (or GUI for short). Using the GUI, you can modify the vis specs using "click"-based interactions at runtime (e.g., gaze and tap in HoloLens). To learn more, check out the GUI tutorial. For now, let’s add z
and color
channels to your visualization using the GUI like shown below:
In addition to the GUI, another way to edit your visualization is via high-level programming - simply put, by editing the vis specs JSON file using any text/code editor. Using this approach allows editing of vis spec parameters that are not exposed in the GUI. Refer to the Grammar Docs for a list of modifiable parameters. For now, let's make some adjustments to make the visualization look nicer.
1. Open the vis specs JSON file Assets/StreamingAssets/DxRSpecs/scatterplot.json using a text/code editor and modify it using the vis specs on the right as a target.
2. Change the mark to sphere. Note: available marks are in the Assets/DxR/Resources/Marks directory and listed in Assets/DxR/Resources/Marks/marks.json file.
3. Set the domain parameters for the scale of x, and y channels to [0, 250] and [0, 50], respectively.
4. Set the title of the y axis to "Miles per Gallon".
5. Set the size channel of the sphere marks to a fixed value of 15 millimeters.
6. Click on the DXRVis game object in the Hierarchy window. In the Inspector window, click the "Update Vis" button (highlighted in yellow in the snapshot below). Any changes to the vis specs will be synchronized with the visualization and the GUI.
Below is an example development set-up using the Unity editor (right) side-by-side with Visual Studio (left) as the external JSON code editor. The vis specs can be modified at runtime, and clicking the "Update Vis" button (highlighted in yellow) in the Inspector window updates the visualization and the GUI.
It is possible to instantly preview your XR scene on the target device, e.g., HoloLens, during development. Follow instructions here for setting this up. With this set-up, you can see the preview of your interactive visualization on the device, (e.g., see snapshot of HoloLens view on the right), and interactively change the vis specs to customize your design using either the GUI or code editor at runtime.