Skip to content

Commit

Permalink
Alter screenshotting feature to be on demand rather than automatic
Browse files Browse the repository at this point in the history
Due to various issues with how the notebook fundamentally
works (asynchronously). It was decided that it would be better for now
to allow the screenshotting of the map to be a manual process. This
commit adds a button which does just that.
  • Loading branch information
danlamanna committed Mar 8, 2017
1 parent 539326e commit be197d1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 90 deletions.
43 changes: 43 additions & 0 deletions js/src/Geonotebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,49 @@ Geonotebook.prototype.load_annotation_buttons = function (Jupyter) {
});

Jupyter.toolbar.add_buttons_group([point_event, rect_event, poly_event]);

// Screenshots
var take_screenshot = Jupyter.actions.register({
handler: function () {
var cell = Jupyter.notebook.get_selected_cell();

if (cell.cell_type === 'code') {
var outputElements = cell.output_area.element.children('.output_area'),
goodOutputs = [];

// Remove any existing screenshots related to this cell
_.each(cell.output_area.outputs, function (output, i) {
if ((_.has(output, 'metadata') && _.has(output.metadata, 'geonotebook_screenshot') &&
output.metadata.geonotebook_screenshot)) {
$(outputElements[i]).remove();
} else {
goodOutputs.push(output);
}
});

cell.output_area.outputs = goodOutputs;

this.map.geojsmap.screenshot().then(function (dataUri) {
cell.output_area.append_output({
output_type: 'display_data',
data: {
'image/png': dataUri.replace(/^data:image\/png;base64,/, "")
},
metadata: {
'geonotebook_screenshot': true
}
});
});
} else {
console.log('Unable to add a screenshot to non-code cell.');
}
}.bind(this),
icon: 'fa-picture-o',
help: 'Capture the map',
help_index: 'zz'
}, 'take_screenshot', 'geonotebook');
Jupyter.toolbar.add_buttons_group([take_screenshot]);
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('g,s', take_screenshot);
};

export default Geonotebook;
6 changes: 0 additions & 6 deletions js/src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,3 @@
cursor: ns-resize;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII=');
}

/* Override of built-in Jupyter notebook rule.
See appendScreenshotAfterExecution docs. */
.output_subarea.output_png {
display: none;
}
4 changes: 1 addition & 3 deletions js/src/extension.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global requirejs */

import { Geonotebook, provenance } from 'geonotebook';
import { Geonotebook } from 'geonotebook';

if (window.require) {
window.require.config({
Expand All @@ -21,8 +21,6 @@ function load_ipython_extension () {
if (Jupyter.kernelselector.current_selection === 'geonotebook2' ||
Jupyter.kernelselector.current_selection === 'geonotebook3') {
Jupyter.geonotebook = new Geonotebook(Jupyter, events);

provenance(Jupyter, events);
}
console.log('loaded geonotebook');
resolve();
Expand Down
4 changes: 1 addition & 3 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import 'geojs';
import Geonotebook from './Geonotebook';
import MapObject from './MapObject';
import * as jsonrpc from './jsonrpc';
import provenance from './provenance';

export {
Geonotebook,
MapObject,
jsonrpc,
provenance
jsonrpc
};
78 changes: 0 additions & 78 deletions js/src/provenance.js

This file was deleted.

0 comments on commit be197d1

Please sign in to comment.