Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions node-red-node-ui-vega/ui_vega.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module.exports = function(RED) {
<script>
(function(scope, val) {

scope.view = null;

function loadScripts(list, callback) {
if (list.length > 0) {
var done = false;
Expand Down Expand Up @@ -66,16 +68,24 @@ function showVega(spec) {
vegaEmbed('#${vid}', spec,
{
actions: false
}).then(result => {
scope.view = result.view;
});
}

function updateData(target, data) {
var changeset = vega.changeset().insert(data);
if (!scope.view) {
return;
}
scope.view.change(target, changeset).runAsync();
}

loadScripts(["https://cdn.jsdelivr.net/npm/[email protected]",
"https://cdn.jsdelivr.net/npm/[email protected]",
"https://cdn.jsdelivr.net/npm/[email protected]"],
function() {
`+
"var vegaSpec = " +vegaSpec +";" +
String.raw`
var vegaSpec = ${vegaSpec};
if (vegaSpec) {
showVega(vegaSpec);
}
Expand All @@ -84,7 +94,11 @@ loadScripts(["https://cdn.jsdelivr.net/npm/[email protected]",
if (!vegaEmbed) {
return;
}
showVega(msg.payload);
if (msg.payload && msg.payload.$schema) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this fix break the compatibility of existing code because $schema property is not mandatory?
May I suggest adding msg.command property for setting data structure for controlling Vega specification?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very sorry.  
I didn't realize that I had failed to send the review results.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. I'll test it out with a msg.command property and update the PR.

showVega(msg.payload);
} else {
updateData(msg.payload.target, msg.payload.data);
}
}
});
}
Expand Down