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

Inset bugfixes #603

Merged
merged 4 commits into from
Dec 9, 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
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