Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tiff viewer to use script entry_point #19151

Merged
merged 6 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
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
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE visualization SYSTEM "../../visualization.dtd">
<visualization name="Tiff Viewer">
<description>Basic Tiff Image visualization</description>
<description>Tiff Image Viewer</description>
<data_sources>
<data_source>
<model_class>HistoryDatasetAssociation</model_class>

<test type="isinstance" test_attr="datatype" result_type="datatype">images.Tiff</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" css="script.css"/>
<entry_point entry_point_type="script" src="script.js" css="script.css"/>
</visualization>
29 changes: 11 additions & 18 deletions config/plugins/visualizations/tiffviewer/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ const App = (props) => {
return <TIFFViewer tiff={props.dataset_url} paginate="bottom" />;
};

/* 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(
<StrictMode>
<App dataset_url={url} />
</StrictMode>
);
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(
<StrictMode>
<App dataset_url={url} />
</StrictMode>
);
Loading