[SIP-6] [Embeddable Charts] Migrate visualization-specific code to js plugin
See original GitHub issueContinued from the discussion in [SIP-5] #5680
There is a decent amount of work to be done to make the visualization plugins are truly independent from the core superset.
Q1: What need to be converted to JS?
@mistercrunch : To make this frontend visualization plugin possible, we’ll need to figure out how to get rid of the visualization-specific backend code in
viz.py
over time, to make sure that visualizations plugins are fully defined as Javascript.
-
One easy step forward is to move the backend’s
query_obj
code, which takesform_data
as input and returns a query object (simple logic). -
The
get_data
method is probably harder to migrate to the front-end (takes adataframe
and returns nested objects), but it can probably be generalized quite a bit, so that it’s not visualization-specific as much as ordering pandas-like operations on the result set.
Q2: Where these new front-end methods should live?
@mistercrunch : I’m guessing you were thinking about export the
adaptor
and using this as an the interface between chart and the visualization plugin. Now I’m thinking we may want to export a more complex object.
export const visualization = {
// Adapter from [SIP-5]
adaptor,
// Convert formData into queryable format
queryGenerator: (formData) => generateQuery(formData),
// Convert formData into post-query operations
dataframeOperations: (formData) => (
['pivot_table', { cols: [formData.cols], rows: formData.groupby }]
),
};
Q3: How to actually implement these two parts?
@mistercrunch : I’m not sure how to model the query vs dataframe operations, should it be incorporate into the query, or made into its own thing. Clearly on the backend we need two abstractions as one is used to interact with connectors (querying) and the other applies to all connectors (dataframe transformation).
@john-bodley : I’m also perplexed as to how to best generalize this. It seems a first step is to map arbitrary data (via a query) into a somewhat generic (potentially visualization aware) form.
@mistercrunch : I also wonder whether we could expose most of the pandas API from the frontend by doing a bit of magic, where the
dataframeOperations
above would somehow do something likegetattr(df, command)(**props)
on the backend.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (12 by maintainers)
Top GitHub Comments
The directory structure for each plugin will look like this. Using
WordCloud
as an example.What is in each file?
1. buildQuery.js
2. transformProps.js
Note: In the future, will replace
slice
with specific fields, such aswidth
,height
, orformData
and perhaps add type (if we use typescript) forformData
3. transformData.js
Transform props that are based on
payload
. The logic formerly inget_data
will be moved here. For the first version, it will be called fromtransformProps.js
, but separated into another function can be useful for future optimization.4. metadata.js
Description of this chart
5.1 WordCloud.js and ReactWordCloud.jsx
For vanilla components that are not React yet, we have been refactoring to make it convertible
WordCloud.js
ReactWordCloud.jsx
5.2 WordCloud.jsx
For components that are already React component
6. adaptor.jsx
Shim to make it work with current Superset app. This file will be deleted after we completely move to the plugin system.
7. plugin.js
This is how a chart plugin is defined. It will replace
adaptor.jsx
.Plugins are installed like this
Then you can use
There is an ongoing work for plugin system in #5882 which explains what happens behind-the-scene in
.install()
. Please see the PR for more details.@conglei
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.