From eec1997d1a7f5ee51b49819e315452c3bb3c88b5 Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 12:40:04 +0300 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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" } } From e82771640766e8b4fc76af984dbcef3911cb65e0 Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 15:28:05 +0300 Subject: [PATCH 5/6] Switch tiff viewer to new script entry_point --- .../tiffviewer/config/tiffviewer.xml | 2 +- .../visualizations/tiffviewer/src/script.js | 29 +++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml b/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml index 99763daa554f..83de34b8b3be 100644 --- a/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml +++ b/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml @@ -14,5 +14,5 @@ dataset_id - + \ No newline at end of file diff --git a/config/plugins/visualizations/tiffviewer/src/script.js b/config/plugins/visualizations/tiffviewer/src/script.js index a16a82253d1a..f97bf19d255a 100644 --- a/config/plugins/visualizations/tiffviewer/src/script.js +++ b/config/plugins/visualizations/tiffviewer/src/script.js @@ -8,22 +8,15 @@ const App = (props) => { return ; }; -/* 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 { root, visualization_config } = JSON.parse(document.getElementById("app").dataset.incoming); -window.bundleEntries = window.bundleEntries || {}; -window.bundleEntries.load = function (options) { - const dataset = options.dataset; - const url = prefixedDownloadUrl(options.root, dataset.download_url); - const root = createRoot(document.getElementById(options.target)); - root.render( - - - - ); - options.chart.state("ok", "Done."); - options.process.resolve(); -}; +const datasetId = visualization_config.dataset_id; + +const url = window.location.origin + root + "api/datasets/" + datasetId + "/display"; + +const rootElement = createRoot(document.getElementById("app")); +rootElement.render( + + + +); From f94b53ef4136042a6bbaf2873a28e8163e818364 Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 16 Nov 2024 15:36:16 +0300 Subject: [PATCH 6/6] Update title to Tiff Image Viewer --- .../plugins/visualizations/tiffviewer/config/tiffviewer.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml b/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml index 83de34b8b3be..84d14366f62c 100644 --- a/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml +++ b/config/plugins/visualizations/tiffviewer/config/tiffviewer.xml @@ -1,13 +1,11 @@ - Basic Tiff Image visualization + Tiff Image Viewer HistoryDatasetAssociation - images.Tiff - dataset_id