Skip to content

Commit

Permalink
Merge pull request galaxyproject#19150 from guerler/update_annotate_i…
Browse files Browse the repository at this point in the history
…mage

Switch update annotate image to new script entry_point
  • Loading branch information
guerler authored Nov 16, 2024
2 parents 5920cab + ebf2889 commit 747bced
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<params>
<param type="dataset" var_name_in_template="hda" required="true">dataset_id</param>
</params>
<entry_point entry_point_type="chart" src="script.js" css="jquery.contextMenu.css"/>
<entry_point entry_point_type="script" src="script.js" css="jquery.contextMenu.css"/>
</visualization>
2 changes: 1 addition & 1 deletion config/plugins/visualizations/annotate_image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
33 changes: 12 additions & 21 deletions config/plugins/visualizations/annotate_image/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down Expand Up @@ -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 || {});
Expand Down Expand Up @@ -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("<img id='image-annotate' src='" + downloadUrl + "' />");
$chartViewer.css("overflow", "auto");
$chartViewer.css("position", "relative");
Expand All @@ -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 { root, visualization_config } = 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);
2 changes: 1 addition & 1 deletion config/plugins/visualizations/example/static/script.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 747bced

Please sign in to comment.