Skip to content

Commit

Permalink
Merge pull request #603 from will-moore/inset_bugfixes
Browse files Browse the repository at this point in the history
Inset bugfixes
  • Loading branch information
will-moore authored Dec 9, 2024
2 parents 1dfb138 + fb13085 commit 7a57378
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/js/models/panel_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@
// delete or update the "inset" Rectangle
let updated = this.get('shapes');
if (panelDeleted) {
updated = updated.filter(shape => shape.id != insetRoiId);
// Delete the inset Rectangle IF there are NO other remaining insets
let insets = figureModel.panels.filter(p => p.get('insetRoiId') == insetRoiId);
if (insets.length == 0) {
updated = updated.filter(shape => shape.id != insetRoiId);
}
this.save('shapes', updated);
} else {
let rect = panel.getViewportAsRect();
updated = updated.map(shape => {
Expand All @@ -111,8 +116,8 @@
}
return shape;
});
this.save('shapes', updated);
}
this.save('shapes', updated);
this.silenceTriggers = false;
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/js/views/figure_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,12 @@
var self = this;
this.model.clearSelected();

// deep copy to make sure we don't accidentally modify clipboard data
let new_panel_json = JSON.parse(JSON.stringify(clipboard_panels));

// first work out the bounding box of clipboard panels
var top, left, bottom, right;
_.each(clipboard_panels, function(m, i) {
_.each(new_panel_json, function(m, i) {
var t = m.y,
l = m.x,
b = t + m.height,
Expand Down Expand Up @@ -647,13 +650,21 @@

// apply offset to clipboard data & paste
// NB: we are modifying the list that is in the clipboard
clipboard_panels = updateRoiIds(clipboard_panels);
new_panel_json = updateRoiIds(new_panel_json);

_.each(clipboard_panels, function(m) {
// Create new panels with offsets
_.each(new_panel_json, function(m) {
m.x = m.x + offset_x;
m.y = m.y + offset_y;
self.model.panels.create(m);
});

// We ALSO update the clipboard data with offsets so that we can paste again
_.each(clipboard_panels, function(m) {
m.x = m.x + offset_x;
m.y = m.y + offset_y;
});

// only pasted panels are selected - simply trigger...
this.model.notifySelectionChange();
},
Expand Down
4 changes: 2 additions & 2 deletions src/js/views/right_panel_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@
'lineWidth': width || 2,
'roiCount': roiCount,
'canPaste': canPaste,
'borderWidth': border ? border.strokeWidth : 2,
'borderColor': border ? border.color.replace('#', '') : 'FFFFFF',
'borderWidth': border ? border.strokeWidth : 5,
'borderColor': border ? border.color.replace('#', '') : 'FFFF00',
'showState': show_btn_state,
}
$('#edit_rois_form').html(this.roisTemplate(json));
Expand Down
9 changes: 3 additions & 6 deletions src/js/views/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ export function getRandomId() {
return parseInt(Math.random() * RANDOM_NUMBER_RANGE);
}

export function newIdFromRandomId(oldId) {
return parseInt((oldId * Math.PI) % RANDOM_NUMBER_RANGE);
}

export function updateRoiIds(panelsJson) {
// If we copy and paste an inset panel AND it's corresponding panel with Rect,
// we don't want changes in viewport/Rect to trigger changes in the panels they
Expand All @@ -296,14 +292,15 @@ export function updateRoiIds(panelsJson) {
let idsToUpdate = insetIdsFromPanels.filter(roiId => insetIdsFromShapes.includes(roiId));

// Update the IDs
let toAdd = getRandomId();
let updatedPanels = panelsJson.map(panelJson => {
if (idsToUpdate.includes(panelJson.insetRoiId)) {
panelJson.insetRoiId = newIdFromRandomId(panelJson.insetRoiId);
panelJson.insetRoiId = (panelJson.insetRoiId + toAdd) % RANDOM_NUMBER_RANGE;
}
if (panelJson.shapes) {
panelJson.shapes.forEach(shape => {
if (idsToUpdate.includes(shape.id)) {
shape.id = newIdFromRandomId(shape.id);
shape.id = (shape.id + toAdd) % RANDOM_NUMBER_RANGE;
}
});
}
Expand Down

0 comments on commit 7a57378

Please sign in to comment.