Skip to content

Fix rendering failure without resources property #36

Description

@EvgeniiaVak

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions