From eec1997d1a7f5ee51b49819e315452c3bb3c88b5 Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 12:40:04 +0300 Subject: [PATCH 1/4] Switch to updated script endpoint --- .../visualizations/annotate_image/config/annotate_image.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/plugins/visualizations/annotate_image/config/annotate_image.xml b/config/plugins/visualizations/annotate_image/config/annotate_image.xml index 0e6781078cf0..b5bcfe76a7ab 100644 --- a/config/plugins/visualizations/annotate_image/config/annotate_image.xml +++ b/config/plugins/visualizations/annotate_image/config/annotate_image.xml @@ -13,5 +13,5 @@ dataset_id - + From 4c052eeb7f446450ba88016cdc324d26f2bb0a1a Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 14:24:22 +0300 Subject: [PATCH 2/4] Adjust visualization to new script endpoint --- .../annotate_image/src/script.js | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/config/plugins/visualizations/annotate_image/src/script.js b/config/plugins/visualizations/annotate_image/src/script.js index 443c1932b6cf..63fb461c65ad 100644 --- a/config/plugins/visualizations/annotate_image/src/script.js +++ b/config/plugins/visualizations/annotate_image/src/script.js @@ -5,12 +5,6 @@ import _ from "underscore"; // Use lighter weight 'core' version of paper since we don't need paperscript import paper from "../node_modules/paper/dist/paper-core.js"; -/* This will be part of the charts/viz standard lib in 23.1 */ -const slashCleanup = /(\/)+/g; -function prefixedDownloadUrl(root, path) { - return `${root}/${path}`.replace(slashCleanup, "/"); -} - const CommandManager = (function () { function CommandManager() {} @@ -60,10 +54,7 @@ const generateUUID = function () { return uuid; }; -window.bundleEntries = window.bundleEntries || {}; -window.bundleEntries.load = function (opt) { - const chart = opt.chart; - const dataset = opt.dataset; +function render(downloadUrl) { const defaults = { color: "red", width: 4, opacity: 0.5 }; $.fn.createCanvas = function (options) { let settings = $.extend({}, defaults, options || {}); @@ -441,17 +432,13 @@ window.bundleEntries.load = function (opt) { }); }; - const downloadUrl = prefixedDownloadUrl(opt.root, dataset.download_url); - fetch(downloadUrl) .then((response) => { if (!response.ok) { throw new Error("Failed to access dataset."); } - return response.text(); - }) - .then((content) => { - const $chartViewer = $("#" + opt.target); + + const $chartViewer = $("#app"); $chartViewer.html(""); $chartViewer.css("overflow", "auto"); $chartViewer.css("position", "relative"); @@ -470,12 +457,16 @@ window.bundleEntries.load = function (opt) { img_height: height, }); }); - - chart.state("ok", "Chart drawn."); - opt.process.resolve(); }) .catch((error) => { - chart.state("failed", error.message); - opt.process.resolve(); + console.error(error.message); }); }; + +const { visualization_config, root } = JSON.parse(document.getElementById("app").dataset.incoming); + +const datasetId = visualization_config.dataset_id; + +const downloadUrl = window.location.origin + root + "api/datasets/" + datasetId + "/display"; + +render(downloadUrl); From 4bdef923b0b0ed852b5a9ff4fac1ba3da70c4493 Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 14:57:41 +0300 Subject: [PATCH 3/4] Fix parsing order --- config/plugins/visualizations/annotate_image/src/script.js | 2 +- config/plugins/visualizations/example/static/script.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/plugins/visualizations/annotate_image/src/script.js b/config/plugins/visualizations/annotate_image/src/script.js index 63fb461c65ad..b90b3cb1901d 100644 --- a/config/plugins/visualizations/annotate_image/src/script.js +++ b/config/plugins/visualizations/annotate_image/src/script.js @@ -463,7 +463,7 @@ function render(downloadUrl) { }); }; -const { visualization_config, root } = JSON.parse(document.getElementById("app").dataset.incoming); +const { root, visualization_config } = JSON.parse(document.getElementById("app").dataset.incoming); const datasetId = visualization_config.dataset_id; diff --git a/config/plugins/visualizations/example/static/script.js b/config/plugins/visualizations/example/static/script.js index e17270b74957..262765a01502 100644 --- a/config/plugins/visualizations/example/static/script.js +++ b/config/plugins/visualizations/example/static/script.js @@ -1,4 +1,4 @@ -const { visualization_config, visualization_plugin, root } = JSON.parse(document.getElementById("app").dataset.incoming); +const { root, visualization_config, visualization_plugin } = JSON.parse(document.getElementById("app").dataset.incoming); const div = Object.assign(document.createElement("div"), { style: "border: 2px solid #25537b; border-radius: 1rem; padding: 1rem" From ebf288913eec28ac7e75f176cbcc67e2cabb7dae Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 15:01:26 +0300 Subject: [PATCH 4/4] Force copy of css, otherwise prevents script rebuilding --- config/plugins/visualizations/annotate_image/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/plugins/visualizations/annotate_image/package.json b/config/plugins/visualizations/annotate_image/package.json index f546269cf52a..ae7cd6a66da9 100644 --- a/config/plugins/visualizations/annotate_image/package.json +++ b/config/plugins/visualizations/annotate_image/package.json @@ -19,7 +19,7 @@ }, "scripts": { "build": "yarn build-css && yarn build-js", - "build-css": "cp 'node_modules/jquery-contextmenu/dist/jquery.contextMenu.css' 'static/'", + "build-css": "cp -f 'node_modules/jquery-contextmenu/dist/jquery.contextMenu.css' 'static/'", "build-js": "parcel build src/script.js --dist-dir static" } }