Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering failure without resources property #36

Open
2 tasks
EvgeniiaVak opened this issue Dec 6, 2019 · 1 comment
Open
2 tasks

Fix rendering failure without resources property #36

EvgeniiaVak opened this issue Dec 6, 2019 · 1 comment

Comments

@EvgeniiaVak
Copy link
Contributor

While trying to render a spec without resources property, e.g. plotly spec that has all the data inside the spec attribute:

{
  "views": [
    {
      "id": 1,
      "specType": "plotly",
      "spec": {
        "data": [
          {
            "type": "pie",
            "values": [
              19,
              26,
              55
            ],
            "labels": [
              "Residential",
              "Non-Residential",
              "Utility"
            ]
          }
        ],
        "layout": {
          "title": "An Example Pie Chart",
          "colorway": [
            "#FBD236",
            "#008A8B"
          ]
        },
        "config": {
          "displayModeBar": false
        }
      }
    }
  ]
}

there is an error:

Uncaught TypeError: Cannot read property '0' of undefined
    at P (main.28e82e8f.chunk.js:1)

which comes from App.js in datapackage-views-js:

    if (!view.resources[0]._values && view.resources[0].data) {
      view.resources[0]._values = view.resources[0].data
    }

and if you try to put empty resource in the spec, then there will be another error:

<div class="TypeError: Cannot read property 'map' of undefined"></div>

from datapackage-render-js in view.js:

function plotlyToPlotly(view) {
  ...
  var rows = getResourceCachedValues(view.resources[0], rowsAsObjects);
  var groupValues = rows.map(function (row) 

because the library always assumes data would be in the resources attribute of the spec.

Tasks

  • ...

Acceptance criteria

  • Different kinds of plotly charts are rendered without exceptions

Analysis

There are several ways to solve the problem:

  • allow plotly spec to have data where it has it - in the view spec itself => update both datapackage-views-js and datapackage-render-js to allow empty "resources" property
  • add the mapping functionality for different types of graphs: there is already plotlyToPlotly function doing that, but it doesn't account for the case with e.g. pie charts (data is located in different attribute - "values", instead of "x" and "y")

Except pie charts there are other types, e.g. heatmap, that use yet another different place in the specs for values, that's why the first approach seems better.

@EvgeniiaVak
Copy link
Contributor Author

Turned out I can already create a view spec with data at plotly specific place - if I specifiy some unused mock resource, so this issue is not a blocker, but would be nice to have to keep specs cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant