metricsgraphics / metrics-graphics

A library optimized for concise and principled data graphics and layouts.
http://metricsgraphicsjs.org
7.46k stars 474 forks source link

Make the list of options programmatically accessible #875

Open wlach opened 6 years ago

wlach commented 6 years ago

Currently libraries like react-metrics-graphics need to manually specify the properties that they want to support. It would be great if metrics graphics exported such a list itself along with a few other pieces of useful metadata, like their type, for use by such libraries.

Probably the place to start here would be to take this existing defaults list and make it into a library export, adding type information:

https://github.com/metricsgraphics/metrics-graphics/blob/8263f26c3a3ad4d07c5aa87d3d22cc494723cce3/src/js/common/data_graphic.js#L18

The data_graphic method could then process the parameters passed in against this list, warning if a particular property was not specified or was specified with the wrong type.

For processing/handling type information, I am tempted to suggest using the prop-types library (used by react). It's pretty tiny:

https://github.com/facebook/prop-types/

After this is done, we could potentially also use this list to generate documentation, eliminating the need for the current manually maintained list of options:

https://github.com/metricsgraphics/metrics-graphics/wiki/List-of-Options

cnwangjie commented 6 years ago

I submit a PR (#893) just now with a simple list of options. I just simply merged the key of the default option objects in all the charts into an array. This does not be used to verify the type of option or generate a document, but it is enough for us to make a component for React or Vue easily.

If we want to use the list for generating documents, we should define a format for setting the type, description, default value, etc. Because the prop list format of React and Vue are not the same, so if we need to make a component with the validation field function, we should use some code to automatically convert to the format required by the framework.

@wlach What do you think about it?