-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18651 from guerler/parse_missing_viz_config
Parse stored config details to script-based visualizations
- Loading branch information
Showing
11 changed files
with
116 additions
and
121 deletions.
There are no files selected for viewing
38 changes: 32 additions & 6 deletions
38
config/plugins/visualizations/common/templates/script_entry_point.mako
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
<%inherit file="visualization_base.mako"/> | ||
|
||
## No stylesheets | ||
<%def name="stylesheets()"></%def> | ||
## No javascript libraries | ||
<%def name="late_javascripts()"> | ||
<% tag_attrs = ' '.join([ '{0}="{1}"'.format( key, attr ) for key, attr in script_attributes.items() ]) %> | ||
<script type="text/javascript" ${tag_attrs}></script> | ||
## Add stylesheet | ||
<%def name="stylesheets()"> | ||
<% script_css = script_attributes.get("css") %> | ||
%if script_css is not None: | ||
<% script_css = script_css if h.is_url(script_css) else f"{static_url}{script_css}" %> | ||
<link rel="stylesheet" href="${script_css}"> | ||
%endif | ||
</%def> | ||
|
||
## Create a container, attach data and import script file | ||
<%def name="get_body()"> | ||
## Collect incoming data | ||
<% | ||
from markupsafe import escape | ||
data_incoming = { | ||
"root": h.url_for("/"), | ||
"visualization_id": visualization_id, | ||
"visualization_name": visualization_name, | ||
"visualization_plugin": visualization_plugin, | ||
"visualization_title": escape(title), | ||
"visualization_config": config } | ||
%> | ||
## Create a container with default identifier `app` | ||
<% container = script_attributes.get("container") or "app" %> | ||
<div id="${container}" data-incoming='${h.dumps(data_incoming)}'></div> | ||
## Add script tag | ||
<% script_src = script_attributes.get("src") %> | ||
<% script_src = script_src if h.is_url(script_src) else f"{static_url}{script_src}" %> | ||
<% script_type = script_attributes.get("type") or "module" %> | ||
<script type="${script_type}" src="${script_src}"></script> | ||
</%def> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE visualization SYSTEM "../../visualization.dtd"> | ||
<visualization name="Example" embeddable="false"> | ||
<description>This is a developer example which demonstrates how to implement and configure a basic d3-based plugin for charts.</description> | ||
<visualization name="Minimal Example" embeddable="false"> | ||
<description>Welcome to the Minimal JS-Based Example Plugin.</description> | ||
<data_sources> | ||
<data_source> | ||
<model_class>HistoryDatasetAssociation</model_class> | ||
<test type="isinstance" test_attr="datatype" result_type="datatype">tabular.Tabular</test> | ||
<test type="isinstance" test_attr="datatype" result_type="datatype">tabular.CSV</test> | ||
<to_param param_attr="id">dataset_id</to_param> | ||
</data_source> | ||
</data_sources> | ||
<params> | ||
<param type="dataset" var_name_in_template="hda" required="true">dataset_id</param> | ||
</params> | ||
<entry_point entry_point_type="chart" src="script.js"/> | ||
<entry_point entry_point_type="script" src="script.js" /> | ||
<settings> | ||
<input> | ||
<name>data_dialog</name> | ||
<label>Some data selector</label> | ||
<type>data_dialog</type> | ||
<multiple>false</multiple> | ||
<name>setting_input</name> | ||
<help>setting help</help> | ||
<type>setting_type</type> | ||
</input> | ||
</settings> | ||
<groups> | ||
<input> | ||
<name>x</name> | ||
<label>Bubble x-position</label> | ||
<type>data_column</type> | ||
<is_numeric>true</is_numeric> | ||
</input> | ||
<input> | ||
<name>y</name> | ||
<label>Bubbles y-position</label> | ||
<type>data_column</type> | ||
<is_numeric>true</is_numeric> | ||
</input> | ||
<input> | ||
<name>z</name> | ||
<label>Bubble size</label> | ||
<type>data_column</type> | ||
<is_numeric>true</is_numeric> | ||
<name>group_input</name> | ||
<help>group help</help> | ||
<type>group_type</type> | ||
</input> | ||
</groups> | ||
</visualization> | ||
<specs> | ||
<spec_name>spec_value</spec_name> | ||
</specs> | ||
</visualization> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { visualization_config, visualization_plugin, root } = JSON.parse(document.getElementById("app").dataset.incoming); | ||
|
||
const div = Object.assign(document.createElement("div"), { | ||
style: "border: 2px solid #25537b; border-radius: 1rem; padding: 1rem" | ||
}); | ||
|
||
const img = Object.assign(document.createElement("img"), { | ||
src: root + visualization_plugin.logo, | ||
style: "height: 3rem" | ||
}); | ||
div.appendChild(img); | ||
|
||
Object.entries(visualization_plugin).forEach(([key, value]) => { | ||
const row = document.createElement("div"); | ||
const spanKey = Object.assign(document.createElement("span"), { | ||
innerText: `${key}: `, | ||
style: "font-weight: bold" | ||
}); | ||
const spanValue = Object.assign(document.createElement("span"), { | ||
innerText: JSON.stringify(value) | ||
}); | ||
row.appendChild(spanKey); | ||
row.appendChild(spanValue); | ||
div.appendChild(row); | ||
}); | ||
|
||
const dataset = Object.assign(document.createElement("div"), { | ||
innerText: `You have selected dataset: ${visualization_config.dataset_id}.`, | ||
style: "font-weight: bold; padding-top: 1rem;" | ||
}); | ||
div.appendChild(dataset); | ||
|
||
document.body.appendChild(div); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters