示例#1
0
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";

// This widget is strongly coupled to the notebook because of the outputarea
// dependency.
var widgets = require("jupyter-js-widgets");
var $ = require("jquery");
var _ = require("underscore");

var OutputModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _model_name: "OutputModel",
        _view_name: "OutputView"
    }),
});

var OutputView = widgets.DOMWidgetView.extend({

    initialize: function (parameters) {
        OutputView.__super__.initialize.apply(this, [parameters]);
        this.listenTo(this.model, 'msg:custom', this._handle_route_msg, this);
    },

    render: function(){
        // TODO: Use jupyter-js-output-area
        requirejs(["notebook/js/outputarea"], (function(outputarea) {
            this.output_area = new outputarea.OutputArea({
                selector: this.$el,
                prompt_area: false,
                events: this.model.widget_manager.notebook.events,
示例#2
0
var WeightedHeatmapLayerModel = GMapsLayerModel.extend({
    defaults: _.extend({}, GMapsLayerModel.prototype.defaults, {
        _view_name: "WeightedHeatmapLayerView",
        _model_name: "WeightedHeatmapLayerModel"
    })
});


var PlainmapModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _view_name: "PlainmapView",
        _model_name: "PlainmapModel",
        _view_module : 'jupyter-gmaps',
        _model_module : 'jupyter-gmaps',
        width: "600px",
        height: "400px"

    })
}, {
    serializers: _.extend({
            layers: {deserialize: widgets.unpack_models}
    }, widgets.DOMWidgetModel.serializers)
});



module.exports = {
    SimpleHeatmapLayerView: SimpleHeatmapLayerView,
    WeightedHeatmapLayerView: WeightedHeatmapLayerView,
    PlainmapView: PlainmapView,
    PlainmapModel: PlainmapModel,
$.resizable = resizable;

var arraybuffer = require('./lib/base64-arraybuffer');
var chemview = require('./lib/chemview');
var ColorScale = require('./lib/scales');

var HEIGHT = 600,
    WIDTH = 600,
    HEIGHT_PX = HEIGHT + 'px',
    WIDTH_PX = WIDTH + 'px';

var ChemviewModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _model_name : 'ChemviewModel',
        _view_name : 'ChemviewView',
        _model_module : 'jupyter-widget-chemview',
        _view_module : 'jupyter-widget-chemview',
        scene : {}
    })
});


var ChemviewView = widgets.DOMWidgetView.extend({

    render: function() {

        var WIDTH = this.model.get('width'),
            HEIGHT = this.model.get('height');

        var that = this;
        var model = this.model;
示例#4
0
var $ = require('jquery');

var TableScope = require('./tableDisplay/tableScope');

require('datatables.net-dt/css/jquery.dataTables.css');
require('datatables.net-colreorder-dt/css/colReorder.dataTables.css');
require('datatables.net-fixedcolumns-dt/css/fixedColumns.dataTables.css');
require('datatables.net-keytable-dt/css/keyTable.dataTables.css');
require('jquery-contextmenu/dist/jquery.contextMenu.css');
require('./tableDisplay/css/datatables.scss');

var TableDisplayModel = widgets.DOMWidgetModel.extend({
  defaults: function() {
    return _.extend({}, widgets.DOMWidgetModel.prototype.defaults.apply(this), {
      _model_name: 'TableDisplayModel',
      _view_name: 'TableDisplayView',
      _model_module: 'beakerx',
      _view_module: 'beakerx'
    });
  }
});


// Custom View. Renders the widget model.
var TableDisplayView = widgets.DOMWidgetView.extend({
  render: function() {
    var that = this;

    this._currentScope = null;

    this.$el.addClass('beaker-table-display');
示例#5
0
// var utils = require('./utils');
var sankeyDiagram = require('d3-sankey-diagram');
var saveSvgAsPng = require('save-svg-as-png');

// Custom Model. Custom widgets models must at least provide default values
// for model attributes, including `_model_name`, `_view_name`, `_model_module`
// and `_view_module` when different from the base class.
//
// When serialiazing entire widget state for embedding, only values different from the
// defaults will be specified.
var SankeyModel = widgets.DOMWidgetModel.extend({
  defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
    _model_name : 'SankeyModel',
    _view_name : 'SankeyView',
    _model_module : 'jupyter-sankey-widget',
    _view_module : 'jupyter-sankey-widget',
    value : {},
    margins : {},
    png : '',
  })
});


// Custom View. Renders the widget model.
var SankeyView = widgets.DOMWidgetView.extend({
  render: function() {
    var layout = this.model.get('layout'),
        width = parseInt(layout.get('width') || "600", 10),
        height = parseInt(layout.get('height') || "400", 10);

    var color = d3.scale.category20();
示例#6
0
文件: Toolbar.js 项目: ivanov/bqplot
var ToolbarModel = widgets.DOMWidgetModel.extend({

    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _model_name: "ToolbarModel",
        _view_name: "Toolbar",
        _model_module: "bqplot",
        _view_module: "bqplot",

        figure: undefined,
        _panning: false,
        _panzoom: null
    }),

    // Backbone attributes:
    // - _panning: Bool
    //       Whether one is currently panning - zooming the specified figure.
    // - _panzoom: Instance of Panzoom or undefined:
    //       The created panzoom interaction. It is undefined at first.
    // Attributes:
    // - cached_interaction: Instance of Interaction or null or undefined.
    //   The cached interaction of the Figure. It is undefined at first
    //   and can take the value of the figure interaction, which can be
    //   null.
    panzoom: function() {
        var figure = this.get("figure");
        if (this.get("_panning")) {
            if (figure) {
                figure.set("interaction", this.cached_interaction);
                figure.save_changes();
            }
            this.set("_panning", false);
            this.save_changes();
        } else {
            if (figure) {
                this.cached_interaction = figure.get("interaction");
                var that = this;
                var panzoom = this.get("_panzoom");
                if (panzoom) {
                    figure.set("interaction", panzoom);
                    figure.save_changes();
                } else {
                    this._create_panzoom_model(figure).then(function (model) {
                        that.set("_panzoom", model);
                        that.save_changes();
                        figure.set("interaction", model);
                        figure.save_changes();
                    })
                }
            }
            this.set("_panning", true);
            this.save_changes();
        }
    },

    reset: function() {
        /**
         * Reset the scales, delete the PanZoom widget, set the figure
         * interaction back to its previous value.
         */
        var figure = this.get("figure");
        var panning = this.get("_panning");
        if (figure) {
            figure.set("interaction", this.cached_interaction);
            figure.save_changes();
            var panzoom = this.get("_panzoom");
            // Should reset_scales be part of PanZoomModel.close()?
            panzoom.reset_scales()
            panzoom.close();
            this.set("_panzoom", null);
            this.set("_panning", false);
            this.save_changes();
        }
    },

    save_png: function() {
        /**
         * Triggers the saving for all the views of that figure.
         */
        // TODO: the toolbar view needs to be associated with a Figure
        // view to avoid calling a model method here.
        var figure = this.get("figure");
        if (figure) {
            figure.save_png();
        }
     },

    _create_panzoom_model: function(figure) {
        /**
         * Creates a panzoom interaction widget for the specified figure.
         *
         * It will discover the relevant scales for the specified figure.
         */
        return this.widget_manager.new_widget({
            model_name: "PanZoomModel",
            model_module: "bqplot",
            widget_class: "bqplot.interacts.PanZoom"
        }).then(function(model) {
            return Promise.all(figure.get("marks")).then(function(marks) {
                var x_scales = [], y_scales = [];
                for (var i=0; i<marks.length; ++i) {
                    var preserve_domain = marks[i].get("preserve_domain");
                    var scales = marks[i].get("scales");
                    _.each(scales, function(v, k) {
                        var dimension = marks[i].get("scales_metadata")[k]["dimension"];
                        if (dimension === "x" && !preserve_domain[k]) {
                             x_scales.push(scales[k]);
                        }
                        if (dimension === "y" && !preserve_domain[k]) {
                             y_scales.push(scales[k]);
                        }
                    });
                }
                model.set("scales", {
                    "x": x_scales,
                    "y": y_scales
                });
                model.save_changes();
                return model;
            });
        });
    },
}, {
    serializers: _.extend({
        figure: { deserialize: widgets.unpack_models },
        _panzoom: { deserialize: widgets.unpack_models },
    }, widgets.DOMWidgetModel.serializers)
});
示例#7
0
var widgets = require('jupyter-js-widgets');
var _ = require('underscore');


// Custom Model. Custom widgets models must at least provide default values
// for model attributes, including `_model_name`, `_view_name`, `_model_module`
// and `_view_module` when different from the base class.
//
// When serialiazing entire widget state for embedding, only values different from the
// defaults will be specified.
var HelloModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _model_name : 'HelloModel',
        _view_name : 'HelloView',
        _model_module : '{{ cookiecutter.npm_package_name }}',
        _view_module : '{{ cookiecutter.npm_package_name }}',
        value : 'Hello World'
    })
});


// Custom View. Renders the widget model.
var HelloView = widgets.DOMWidgetView.extend({
    render: function() {
        this.value_changed();
        this.model.on('change:value', this.value_changed, this);
    },

    value_changed: function() {
        this.el.textContent = this.model.get('value');
    }
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
var widgets = require('jupyter-js-widgets');
var _ = require('underscore');
var $3Dmol = require('./3Dmol');

var DONOTSEND = ['GLViewer','GLModel'];

var MolWidget3DModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _model_name : 'MolWidget3DModel',
        _view_name : 'MolWidget3DView',
        _model_module : 'nbmolviz-js',
        _view_module : 'nbmolviz-js'
    })
});


var MolWidget3DView = widgets.DOMWidgetView.extend({
    render: function render() {
        document.last_3d_widget = this;
        this._where = this.model.get('_where');
        this.messages = [];
        this.viewerId = this.model.get('viewerId');
        if (this._where == 'inline') {
            this.mydiv = document.createElement('div');
            this.mydiv.style.width = this.model.get('_width');
            this.mydiv.style.height = this.model.get('_height');
示例#9
0
var LeafletMapModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _view_name : "LeafletMapView",
        _model_name : "LeafletMapModel",
        _model_module : "jupyter-leaflet",
        _view_module : "jupyter-leaflet",

        center : def_loc,
        width : "600px",
        height : "400px",
        zoom_start : 12,
        zoom : 12,
        max_zoom : 18,
        min_zoom : 1,

        dragging : true,
        touch_zoom : true,
        scroll_wheel_zoom : false,
        double_click_zoom : true,
        box_zoom : true,
        tap : true,
        tap_tolerance : 15,
        world_copy_jump : false,
        close_popup_on_click : true,
        bounce_at_zoom_limits : true,
        keyboard : true,
        keyboard_pan_offset : 80,
        keyboard_zoom_offset : 1,
        inertia : true,
        inertia_deceleration : 3000,
        inertia_max_speed : 1500,
        // inertia_threshold : int(?)
        zoom_control : true,
        attribution_control : true,
        // fade_animation : bool(?),
        // zoom_animation : bool(?),
        zoom_animation_threshold : 4,
        // marker_zoom_animation : bool(?),
        _south : def_loc[0],
        _north : def_loc[0],
        _east : def_loc[1],
        _west : def_loc[1],
        options : [],
        layers : [],
        controls : []
    })
}, {
    serializers: _.extend({
        layers : { deserialize: widgets.unpack_models },
        controls : { deserialize: widgets.unpack_models }
    }, widgets.DOMWidgetModel.serializers)
});
示例#10
0
var widgets = require('jupyter-js-widgets');
var _ = require('underscore');


// Custom Model. Custom widgets models must at least provide default values
// for model attributes, including `_model_name`, `_view_name`, `_model_module`
// and `_view_module` when different from the base class.
//
// When serialiazing entire widget state for embedding, only values different from the
// defaults will be specified.
var HelloModel = widgets.DOMWidgetModel.extend({
    defaults: _.extend({}, widgets.DOMWidgetModel.prototype.defaults, {
        _model_name : 'HelloModel',
        _view_name : 'HelloView',
        _model_module : 'ipython-threejs',
        _view_module : 'ipython-threejs',
        value : 'Hello World'
    })
});


// Custom View. Renders the widget model.
var HelloView = widgets.DOMWidgetView.extend({
    render: function() {
        this.value_changed();
        this.model.on('change:value', this.value_changed, this);
    },

    value_changed: function() {
        this.el.textContent = this.model.get('value');
    }