vega / voyager-electron

Creative Commons Zero v1.0 Universal
4 stars 1 forks source link

Fix loading vega-lite specs with data URLs #24

Open espressoroaster opened 7 years ago

espressoroaster commented 7 years ago

Voyager-electron currently parses Vega-Lite spec data URLs relative to the program rather than relative to the spec as you would expect.

File structure: image

Error:

image

cars_scatterplot.json:

{
  "description": "A scatterplot showing horsepower and miles per gallons for various cars.",
  "data": {"url": "data/cars.json"},
  "mark": "point",
  "encoding": {
    "x": {"field": "Horsepower","type": "quantitative"},
    "y": {"field": "Miles_per_Gallon","type": "quantitative"}
  }
}

cars.json: https://raw.githubusercontent.com/vega/vega-editor/redux/data/cars.json

espressoroaster commented 7 years ago

We just need to prepend the remainder of the file path from voyager-electron to the VLspec to convert the VLspec's data URL into an absolute URL.

espressoroaster commented 7 years ago

The fp variable in electron should contain the absolute URL to the spec being opened. From there we'll need to distinguish between whether we are loading in-line data, data from an absolute URL, or data from a relative URL. For the latter case we will need to be modify the spec's relative data path to an absolute path by prepending the path (sans filename) from fp.