|
7 | 7 | import { recoverFigureFromStorage, |
8 | 8 | clearFigureFromStorage, |
9 | 9 | figureConfirmDialog, |
10 | | - getJson, |
| 10 | + getJsonWithCredentials, |
11 | 11 | saveFigureToStorage, |
12 | 12 | normalizeZProjectionBounds} from "../views/util"; |
| 13 | + import { loadZarrForPanel } from "./zarr_utils"; |
13 | 14 |
|
14 | 15 | // Version of the json file we're saving. |
15 | 16 | // This only needs to increment when we make breaking changes (not linked to release versions.) |
|
66 | 67 | var load_url = BASE_WEBFIGURE_URL + "load_web_figure/" + fileId + "/", |
67 | 68 | self = this; |
68 | 69 |
|
69 | | - getJson(load_url).then(data => { |
| 70 | + getJsonWithCredentials(load_url).then(data => { |
70 | 71 | data.fileId = fileId; |
71 | 72 | self.load_from_JSON(data); |
72 | 73 | self.set('unsaved', false); |
|
310 | 311 | if (iids.length > 0) { |
311 | 312 | var ptUrl = BASE_WEBFIGURE_URL + 'pixels_type/'; |
312 | 313 | ptUrl += '?image=' + iids.join('&image='); |
313 | | - getJson(ptUrl).then(data => { |
| 314 | + getJsonWithCredentials(ptUrl).then(data => { |
314 | 315 | // Update all panels |
315 | 316 | // NB: By the time that this callback runs, the panels will have been created |
316 | 317 | self.panels.forEach(function(p){ |
|
533 | 534 | // new image panels appropriately in a grid. |
534 | 535 | var invalidIds = []; |
535 | 536 | for (var i=0; i<iIds.length; i++) { |
| 537 | + console.log("Adding image", iIds[i]); |
| 538 | + if (iIds[i].includes("http")) { |
| 539 | + this.importZarrImage(iIds[i], coords, i); |
| 540 | + continue; |
| 541 | + } |
536 | 542 | var imgId = iIds[i].replace("|", ""), |
537 | 543 | validId = parseInt(imgId, 10) + "", |
538 | 544 | imgDataUrl = BASE_WEBFIGURE_URL + 'imgData/' + validId + '/'; |
|
548 | 554 | } |
549 | 555 | }, |
550 | 556 |
|
| 557 | + updateCoordsAndPanelCoords(panel_json, coords, index) { |
| 558 | + // update panel_json and coords |
| 559 | + coords.spacer = coords.spacer || panel_json.orig_width/20; |
| 560 | + var full_width = (coords.colCount * (panel_json.orig_width + coords.spacer)) - coords.spacer, |
| 561 | + full_height = (coords.rowCount * (panel_json.orig_height + coords.spacer)) - coords.spacer; |
| 562 | + coords.scale = coords.paper_width / (full_width + (2 * coords.spacer)); |
| 563 | + coords.scale = Math.min(coords.scale, 1); // only scale down |
| 564 | + // For the FIRST IMAGE ONLY (coords.px etc undefined), we |
| 565 | + // need to work out where to start (px,py) now that we know size of panel |
| 566 | + // (assume all panels are same size) |
| 567 | + coords.px = coords.px || coords.c.x - (full_width * coords.scale)/2; |
| 568 | + coords.py = coords.py || coords.c.y - (full_height * coords.scale)/2; |
| 569 | + // calculate panel coordinates from index... |
| 570 | + var row = parseInt(index / coords.colCount, 10); |
| 571 | + var col = index % coords.colCount; |
| 572 | + var panelX = coords.px + ((panel_json.orig_width + coords.spacer) * coords.scale * col); |
| 573 | + var panelY = coords.py + ((panel_json.orig_height + coords.spacer) * coords.scale * row); |
| 574 | + |
| 575 | + // update panel_json |
| 576 | + panel_json.x = panelX; |
| 577 | + panel_json.y = panelY; |
| 578 | + panel_json.width = panel_json.orig_width * coords.scale; |
| 579 | + panel_json.height = panel_json.orig_height * coords.scale; |
| 580 | + }, |
| 581 | + |
| 582 | + importZarrImage: async function(zarrUrl, coords, index) { |
| 583 | + if (zarrUrl.endsWith("/")) { |
| 584 | + zarrUrl = zarrUrl.slice(0, -1); |
| 585 | + } |
| 586 | + this.set('loading_count', this.get('loading_count') + 1); |
| 587 | + |
| 588 | + let panel_json = await loadZarrForPanel(zarrUrl); |
| 589 | + if (panel_json.Error) { |
| 590 | + let zarrErr = panel_json.Error; |
| 591 | + for (let fmt of ["bioformats2raw.layout", "OME-Zarr Plates"]) { |
| 592 | + if (zarrErr.includes(fmt)) { |
| 593 | + zarrErr = `Error loading Zarr ${zarrUrl}: |
| 594 | + <p>${fmt} not currently supported.</p> |
| 595 | + <p>Please <a href="https://ome.github.io/ome-ngff-validator/?source=${encodeURIComponent(zarrUrl)}" target="_blank"> |
| 596 | + open in the OME-NGFF Validator</a> to choose a single Image url.</p> |
| 597 | + `; |
| 598 | + } |
| 599 | + } |
| 600 | + if (zarrErr.includes("File not found")) { |
| 601 | + zarrErr = `Error loading Zarr from <br/>${zarrUrl}: |
| 602 | + <p>File not found (No <code>zarr.json</code> or <code>.zattrs</code>)</p>`; |
| 603 | + } |
| 604 | + figureConfirmDialog( |
| 605 | + "Zarr Load Error", |
| 606 | + zarrErr, |
| 607 | + ["OK"] |
| 608 | + ); |
| 609 | + // alert(`Error loading Zarr ${zarrUrl}: ${panel_json.Error}`); |
| 610 | + this.set('loading_count', this.get('loading_count') - 1); |
| 611 | + return; |
| 612 | + } |
| 613 | + |
| 614 | + // coords (px, py etc) are incremented for each panel added |
| 615 | + this.updateCoordsAndPanelCoords(panel_json, coords, index) |
| 616 | + |
| 617 | + this.set('loading_count', this.get('loading_count') - 1); |
| 618 | + // create Panel (and select it) |
| 619 | + // We do some additional processing in Panel.parse() |
| 620 | + this.panels.create(panel_json, {'parse': true}).set('selected', true); |
| 621 | + this.notifySelectionChange(); |
| 622 | + }, |
| 623 | + |
551 | 624 | importImage: function(imgDataUrl, coords, baseUrl, index) { |
552 | 625 |
|
553 | 626 | var self = this, |
|
580 | 653 | return; |
581 | 654 | } |
582 | 655 |
|
583 | | - coords.spacer = coords.spacer || data.size.width/20; |
584 | | - var full_width = (coords.colCount * (data.size.width + coords.spacer)) - coords.spacer, |
585 | | - full_height = (coords.rowCount * (data.size.height + coords.spacer)) - coords.spacer; |
586 | | - coords.scale = coords.paper_width / (full_width + (2 * coords.spacer)); |
587 | | - coords.scale = Math.min(coords.scale, 1); // only scale down |
588 | | - // For the FIRST IMAGE ONLY (coords.px etc undefined), we |
589 | | - // need to work out where to start (px,py) now that we know size of panel |
590 | | - // (assume all panels are same size) |
591 | | - coords.px = coords.px || coords.c.x - (full_width * coords.scale)/2; |
592 | | - coords.py = coords.py || coords.c.y - (full_height * coords.scale)/2; |
593 | | - |
594 | | - // calculate panel coordinates from index... |
595 | | - var row = parseInt(index / coords.colCount, 10); |
596 | | - var col = index % coords.colCount; |
597 | | - var panelX = coords.px + ((data.size.width + coords.spacer) * coords.scale * col); |
598 | | - var panelY = coords.py + ((data.size.height + coords.spacer) * coords.scale * row); |
599 | | - |
600 | 656 | // ****** This is the Data Model ****** |
601 | 657 | //------------------------------------- |
602 | 658 | // Any changes here will create a new version |
|
617 | 673 | 'channels': data.channels, |
618 | 674 | 'orig_width': data.size.width, |
619 | 675 | 'orig_height': data.size.height, |
620 | | - 'x': panelX, |
621 | | - 'y': panelY, |
| 676 | + 'x': 0, |
| 677 | + 'y': 0, |
622 | 678 | 'datasetName': data.meta.datasetName, |
623 | 679 | 'datasetId': data.meta.datasetId, |
624 | 680 | 'pixel_size_x': data.pixel_size.valueX, |
|
636 | 692 | if (baseUrl) { |
637 | 693 | n.baseUrl = baseUrl; |
638 | 694 | } |
| 695 | + |
| 696 | + // coords (px, py etc) are incremented for each panel added |
| 697 | + self.updateCoordsAndPanelCoords(n, coords, index); |
| 698 | + |
639 | 699 | // create Panel (and select it) |
640 | 700 | // We do some additional processing in Panel.parse() |
641 | 701 | self.panels.create(n, {'parse': true}).set('selected', true); |
|
0 commit comments