rawgraphs / rawgraphs-charts

A curated selection of charts provided through RAWGraphs interface
https://rawgraphs.io/
Apache License 2.0
95 stars 42 forks source link

throwing an error in charts #46

Closed mikima closed 3 years ago

mikima commented 3 years ago

Is it possible to throw an error from the chart to RAWGraphs interface? For example, in radar chart you should drop at minimum three dimensions to see something. Would be nice to tell it to the user

bianchimro commented 3 years ago

hi @mikima yes, it's possible by just throwing a js error in your render function

throw new Error("Hello error")

that renders like this:

Screenshot 2021-01-11 at 21 54 02

There was a problem showing the error in the frontend, I just fixed it here https://github.com/rawgraphs/rawgraphs-frontend/commit/9a539ce16c9b794c1675991f94e459b6bc932208 (still needs some styling, but there was a positioning issues and the error was sometimes hidden)

Your specific use case is covered by the dimensions api. When you declare a dimension, you can set minValues and maxValues properties (indipendently) to require/limit the maximum number of values that can be mapped on a multiple dimension. Like:

export const dimensions = [
  {
    id: 'axes',
    name: 'spokes',
    validTypes: ['number'],
    required: true,
    multiple: true,
    minValues: 2,
    aggregation: true,
    aggregationDefault: {
      number: 'sum',
      string: 'csvDistinct',
      date: 'csvDistinct',
    },
  },
  ...
]

This should the way to do it but:

mikima commented 3 years ago

Great! Thanks