@quartic/bokehjs
Version:
Interactive, novel data visualization
1,338 lines (1,325 loc) • 1.39 MB
JavaScript
window.Bokeh = Bokeh = (function() { var define = undefined; return (function outer(modules, cache, entry) {
function newRequire(name) {
if (!cache[name]) {
if (!modules[name]) {
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
}
var m = cache[name] = {exports: {}};
var moduleRequire = function foo(x) {
var id = modules[name][1][x];
return newRequire(id ? id : x);
}
moduleRequire.modules = newRequire.modules;
modules[name][0].call(m.exports, moduleRequire, m, m.exports, outer, modules, cache, entry);
}
return cache[name].exports;
}
newRequire.modules = modules;
var main = newRequire(entry[0]);
main.require = newRequire;
return main;
})
({"base":[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _all_models, hasProp = {}.hasOwnProperty;
var models = require("./models/index");
var object_1 = require("./core/util/object");
exports.overrides = {};
_all_models = object_1.clone(models);
exports.Models = function (name) {
var model, ref;
model = (ref = exports.overrides[name]) != null ? ref : _all_models[name];
if (model == null) {
throw new Error("Model `" + name + "' does not exist. This could be due to a widget or a custom model not being registered before first usage.");
}
return model;
};
exports.Models.register = function (name, model) {
return exports.overrides[name] = model;
};
exports.Models.unregister = function (name) {
return delete exports.overrides[name];
};
exports.Models.register_models = function (models, force, errorFn) {
var model, name, results;
if (force == null) {
force = false;
}
if (errorFn == null) {
errorFn = null;
}
if (models == null) {
return;
}
results = [];
for (name in models) {
if (!hasProp.call(models, name))
continue;
model = models[name];
if (force || !_all_models.hasOwnProperty(name)) {
results.push(_all_models[name] = model);
}
else {
results.push(typeof errorFn === "function" ? errorFn(name) : void 0);
}
}
return results;
};
exports.Models.registered_names = function () {
return Object.keys(_all_models);
};
exports.index = {};
},{"./core/util/object":"core/util/object","./models/index":"models/index"}],"client":[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ClientConnection, ClientSession, Message, message_handlers;
var es6_promise_1 = require("es6-promise");
var logging_1 = require("./core/logging");
var string_1 = require("./core/util/string");
var object_1 = require("./core/util/object");
var document_1 = require("./document");
exports.DEFAULT_SERVER_WEBSOCKET_URL = "ws://localhost:5006/ws";
exports.DEFAULT_SESSION_ID = "default";
Message = (function () {
function Message(header1, metadata1, content1) {
this.header = header1;
this.metadata = metadata1;
this.content = content1;
this.buffers = [];
}
Message.assemble = function (header_json, metadata_json, content_json) {
var content, e, header, metadata;
try {
header = JSON.parse(header_json);
metadata = JSON.parse(metadata_json);
content = JSON.parse(content_json);
return new Message(header, metadata, content);
}
catch (error1) {
e = error1;
logging_1.logger.error("Failure parsing json " + e + " " + header_json + " " + metadata_json + " " + content_json, e);
throw e;
}
};
Message.create_header = function (msgtype, options) {
var header;
header = {
'msgid': string_1.uniqueId(),
'msgtype': msgtype
};
return object_1.extend(header, options);
};
Message.create = function (msgtype, header_options, content) {
var header;
if (content == null) {
content = {};
}
header = Message.create_header(msgtype, header_options);
return new Message(header, {}, content);
};
Message.prototype.send = function (socket) {
var content_json, e, header_json, metadata_json;
try {
header_json = JSON.stringify(this.header);
metadata_json = JSON.stringify(this.metadata);
content_json = JSON.stringify(this.content);
socket.send(header_json);
socket.send(metadata_json);
return socket.send(content_json);
}
catch (error1) {
e = error1;
logging_1.logger.error("Error sending ", this, e);
throw e;
}
};
Message.prototype.complete = function () {
if ((this.header != null) && (this.metadata != null) && (this.content != null)) {
if ('num_buffers' in this.header) {
return this.buffers.length === this.header['num_buffers'];
}
else {
return true;
}
}
else {
return false;
}
};
Message.prototype.add_buffer = function (buffer) {
return this.buffers.push(buffer);
};
Message.prototype._header_field = function (field) {
if (field in this.header) {
return this.header[field];
}
else {
return null;
}
};
Message.prototype.msgid = function () {
return this._header_field('msgid');
};
Message.prototype.msgtype = function () {
return this._header_field('msgtype');
};
Message.prototype.sessid = function () {
return this._header_field('sessid');
};
Message.prototype.reqid = function () {
return this._header_field('reqid');
};
Message.prototype.problem = function () {
if (!('msgid' in this.header)) {
return "No msgid in header";
}
else if (!('msgtype' in this.header)) {
return "No msgtype in header";
}
else {
return null;
}
};
return Message;
})();
message_handlers = {
'PATCH-DOC': function (connection, message) {
return connection._for_session(function (session) {
return session._handle_patch(message);
});
},
'OK': function (connection, message) {
return logging_1.logger.debug("Unhandled OK reply to " + (message.reqid()));
},
'ERROR': function (connection, message) {
return logging_1.logger.error("Unhandled ERROR reply to " + (message.reqid()) + ": " + message.content['text']);
}
};
ClientConnection = (function () {
ClientConnection._connection_count = 0;
function ClientConnection(url1, id, args_string1, _on_have_session_hook, _on_closed_permanently_hook) {
this.url = url1;
this.id = id;
this.args_string = args_string1;
this._on_have_session_hook = _on_have_session_hook;
this._on_closed_permanently_hook = _on_closed_permanently_hook;
this._number = ClientConnection._connection_count;
ClientConnection._connection_count = this._number + 1;
if (this.url == null) {
this.url = exports.DEFAULT_SERVER_WEBSOCKET_URL;
}
if (this.id == null) {
this.id = exports.DEFAULT_SESSION_ID;
}
logging_1.logger.debug("Creating websocket " + this._number + " to '" + this.url + "' session '" + this.id + "'");
this.socket = null;
this.closed_permanently = false;
this._fragments = [];
this._partial = null;
this._current_handler = null;
this._pending_ack = null;
this._pending_replies = {};
this.session = null;
}
ClientConnection.prototype._for_session = function (f) {
if (this.session !== null) {
return f(this.session);
}
};
ClientConnection.prototype.connect = function () {
var error, ref, versioned_url;
if (this.closed_permanently) {
return es6_promise_1.Promise.reject(new Error("Cannot connect() a closed ClientConnection"));
}
if (this.socket != null) {
return es6_promise_1.Promise.reject(new Error("Already connected"));
}
this._fragments = [];
this._partial = null;
this._pending_replies = {};
this._current_handler = null;
try {
versioned_url = this.url + "?bokeh-protocol-version=1.0&bokeh-session-id=" + this.id;
if (((ref = this.args_string) != null ? ref.length : void 0) > 0) {
versioned_url += "&" + this.args_string;
}
if (window.MozWebSocket != null) {
this.socket = new MozWebSocket(versioned_url);
}
else {
this.socket = new WebSocket(versioned_url);
}
return new es6_promise_1.Promise((function (_this) {
return function (resolve, reject) {
_this.socket.binarytype = "arraybuffer";
_this.socket.onopen = function () {
return _this._on_open(resolve, reject);
};
_this.socket.onmessage = function (event) {
return _this._on_message(event);
};
_this.socket.onclose = function (event) {
return _this._on_close(event);
};
return _this.socket.onerror = function () {
return _this._on_error(reject);
};
};
})(this));
}
catch (error1) {
error = error1;
logging_1.logger.error("websocket creation failed to url: " + this.url);
logging_1.logger.error(" - " + error);
return es6_promise_1.Promise.reject(error);
}
};
ClientConnection.prototype.close = function () {
if (!this.closed_permanently) {
logging_1.logger.debug("Permanently closing websocket connection " + this._number);
this.closed_permanently = true;
if (this.socket != null) {
this.socket.close(1000, "close method called on ClientConnection " + this._number);
}
this._for_session(function (session) {
return session._connection_closed();
});
if (this._on_closed_permanently_hook != null) {
this._on_closed_permanently_hook();
return this._on_closed_permanently_hook = null;
}
}
};
ClientConnection.prototype._schedule_reconnect = function (milliseconds) {
var retry;
retry = (function (_this) {
return function () {
if (true || _this.closed_permanently) {
if (!_this.closed_permanently) {
logging_1.logger.info("Websocket connection " + _this._number + " disconnected, will not attempt to reconnect");
}
}
else {
logging_1.logger.debug("Attempting to reconnect websocket " + _this._number);
return _this.connect();
}
};
})(this);
return setTimeout(retry, milliseconds);
};
ClientConnection.prototype.send = function (message) {
var e;
try {
if (this.socket === null) {
throw new Error("not connected so cannot send " + message);
}
return message.send(this.socket);
}
catch (error1) {
e = error1;
return logging_1.logger.error("Error sending message ", e, message);
}
};
ClientConnection.prototype.send_event = function (event) {
var message;
message = Message.create('EVENT', {}, JSON.stringify(event));
return this.send(message);
};
ClientConnection.prototype.send_with_reply = function (message) {
var promise;
promise = new es6_promise_1.Promise((function (_this) {
return function (resolve, reject) {
_this._pending_replies[message.msgid()] = [resolve, reject];
return _this.send(message);
};
})(this));
return promise.then(function (message) {
if (message.msgtype() === 'ERROR') {
throw new Error("Error reply " + message.content['text']);
}
else {
return message;
}
}, function (error) {
throw error;
});
};
ClientConnection.prototype._pull_doc_json = function () {
var message, promise;
message = Message.create('PULL-DOC-REQ', {});
promise = this.send_with_reply(message);
return promise.then(function (reply) {
if (!('doc' in reply.content)) {
throw new Error("No 'doc' field in PULL-DOC-REPLY");
}
return reply.content['doc'];
}, function (error) {
throw error;
});
};
ClientConnection.prototype._repull_session_doc = function () {
if (this.session === null) {
logging_1.logger.debug("Pulling session for first time");
}
else {
logging_1.logger.debug("Repulling session");
}
return this._pull_doc_json().then((function (_this) {
return function (doc_json) {
var document, patch, patch_message;
if (_this.session === null) {
if (_this.closed_permanently) {
return logging_1.logger.debug("Got new document after connection was already closed");
}
else {
document = document_1.Document.from_json(doc_json);
patch = document_1.Document._compute_patch_since_json(doc_json, document);
if (patch.events.length > 0) {
logging_1.logger.debug("Sending " + patch.events.length + " changes from model construction back to server");
patch_message = Message.create('PATCH-DOC', {}, patch);
_this.send(patch_message);
}
_this.session = new ClientSession(_this, document, _this.id);
logging_1.logger.debug("Created a new session from new pulled doc");
if (_this._on_have_session_hook != null) {
_this._on_have_session_hook(_this.session);
return _this._on_have_session_hook = null;
}
}
}
else {
_this.session.document.replace_with_json(doc_json);
return logging_1.logger.debug("Updated existing session with new pulled doc");
}
};
})(this), function (error) {
throw error;
})["catch"](function (error) {
if (console.trace != null) {
console.trace(error);
}
return logging_1.logger.error("Failed to repull session " + error);
});
};
ClientConnection.prototype._on_open = function (resolve, reject) {
logging_1.logger.info("Websocket connection " + this._number + " is now open");
this._pending_ack = [resolve, reject];
return this._current_handler = (function (_this) {
return function (message) {
return _this._awaiting_ack_handler(message);
};
})(this);
};
ClientConnection.prototype._on_message = function (event) {
var e;
try {
return this._on_message_unchecked(event);
}
catch (error1) {
e = error1;
return logging_1.logger.error("Error handling message: " + e + ", " + event);
}
};
ClientConnection.prototype._on_message_unchecked = function (event) {
var msg, problem;
if (this._current_handler == null) {
logging_1.logger.error("got a message but haven't set _current_handler");
}
if (event.data instanceof ArrayBuffer) {
if ((this._partial != null) && !this._partial.complete()) {
this._partial.add_buffer(event.data);
}
else {
this._close_bad_protocol("Got binary from websocket but we were expecting text");
}
}
else if (this._partial != null) {
this._close_bad_protocol("Got text from websocket but we were expecting binary");
}
else {
this._fragments.push(event.data);
if (this._fragments.length === 3) {
this._partial = Message.assemble(this._fragments[0], this._fragments[1], this._fragments[2]);
this._fragments = [];
problem = this._partial.problem();
if (problem !== null) {
this._close_bad_protocol(problem);
}
}
}
if ((this._partial != null) && this._partial.complete()) {
msg = this._partial;
this._partial = null;
return this._current_handler(msg);
}
};
ClientConnection.prototype._on_close = function (event) {
var pop_pending, promise_funcs;
logging_1.logger.info("Lost websocket " + this._number + " connection, " + event.code + " (" + event.reason + ")");
this.socket = null;
if (this._pending_ack != null) {
this._pending_ack[1](new Error("Lost websocket connection, " + event.code + " (" + event.reason + ")"));
this._pending_ack = null;
}
pop_pending = (function (_this) {
return function () {
var promise_funcs, ref, reqid;
ref = _this._pending_replies;
for (reqid in ref) {
promise_funcs = ref[reqid];
delete _this._pending_replies[reqid];
return promise_funcs;
}
return null;
};
})(this);
promise_funcs = pop_pending();
while (promise_funcs !== null) {
promise_funcs[1]("Disconnected");
promise_funcs = pop_pending();
}
if (!this.closed_permanently) {
return this._schedule_reconnect(2000);
}
};
ClientConnection.prototype._on_error = function (reject) {
logging_1.logger.debug("Websocket error on socket " + this._number);
return reject(new Error("Could not open websocket"));
};
ClientConnection.prototype._close_bad_protocol = function (detail) {
logging_1.logger.error("Closing connection: " + detail);
if (this.socket != null) {
return this.socket.close(1002, detail);
}
};
ClientConnection.prototype._awaiting_ack_handler = function (message) {
if (message.msgtype() === "ACK") {
this._current_handler = (function (_this) {
return function (message) {
return _this._steady_state_handler(message);
};
})(this);
this._repull_session_doc();
if (this._pending_ack != null) {
this._pending_ack[0](this);
return this._pending_ack = null;
}
}
else {
return this._close_bad_protocol("First message was not an ACK");
}
};
ClientConnection.prototype._steady_state_handler = function (message) {
var promise_funcs;
if (message.reqid() in this._pending_replies) {
promise_funcs = this._pending_replies[message.reqid()];
delete this._pending_replies[message.reqid()];
return promise_funcs[0](message);
}
else if (message.msgtype() in message_handlers) {
return message_handlers[message.msgtype()](this, message);
}
else {
return logging_1.logger.debug("Doing nothing with message " + (message.msgtype()));
}
};
return ClientConnection;
})();
ClientSession = (function () {
function ClientSession(_connection, document1, id) {
this._connection = _connection;
this.document = document1;
this.id = id;
this.document_listener = (function (_this) {
return function (event) {
return _this._document_changed(event);
};
})(this);
this.document.on_change(this.document_listener);
this.event_manager = this.document.event_manager;
this.event_manager.session = this;
}
ClientSession.prototype.close = function () {
return this._connection.close();
};
ClientSession.prototype.send_event = function (type) {
return this._connection.send_event(type);
};
ClientSession.prototype._connection_closed = function () {
return this.document.remove_on_change(this.document_listener);
};
ClientSession.prototype.request_server_info = function () {
var message, promise;
message = Message.create('SERVER-INFO-REQ', {});
promise = this._connection.send_with_reply(message);
return promise.then(function (reply) {
return reply.content;
});
};
ClientSession.prototype.force_roundtrip = function () {
return this.request_server_info().then(function (ignored) {
return void 0;
});
};
ClientSession.prototype._document_changed = function (event) {
var patch;
if (event.setter_id === this.id) {
return;
}
if (event instanceof document_1.ModelChangedEvent && !(event.attr in event.model.serializable_attributes())) {
return;
}
patch = Message.create('PATCH-DOC', {}, this.document.create_json_patch([event]));
return this._connection.send(patch);
};
ClientSession.prototype._handle_patch = function (message) {
return this.document.apply_json_patch(message.content, this.id);
};
return ClientSession;
})();
exports.pull_session = function (url, session_id, args_string) {
var connection, promise, rejecter;
rejecter = null;
connection = null;
promise = new es6_promise_1.Promise(function (resolve, reject) {
connection = new ClientConnection(url, session_id, args_string, function (session) {
var e;
try {
return resolve(session);
}
catch (error1) {
e = error1;
logging_1.logger.error("Promise handler threw an error, closing session " + error);
session.close();
throw e;
}
}, function () {
return reject(new Error("Connection was closed before we successfully pulled a session"));
});
return connection.connect().then(function (whatever) { }, function (error) {
logging_1.logger.error("Failed to connect to Bokeh server " + error);
throw error;
});
});
promise.close = function () {
return connection.close();
};
return promise;
};
},{"./core/logging":"core/logging","./core/util/object":"core/util/object","./core/util/string":"core/util/string","./document":"document","es6-promise":"es6-promise"}],"core/backbone":[function(require,module,exports){
"use strict";
// Backbone.js 1.3.3
Object.defineProperty(exports, "__esModule", { value: true });
// (c) 2010-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
var events_1 = require("./events");
var eq_1 = require("./util/eq");
var object_1 = require("./util/object");
// Backbone.Model
// --------------
// Backbone **Models** are the basic data object in the framework --
// frequently representing a row in a table in a database on your server.
// A discrete chunk of data and a bunch of useful, related methods for
// performing computations and transformations on that data.
// Create a new model with the specified attributes.
exports.Model = function (attributes, options) {
var attrs = attributes || {};
options || (options = {});
this.attributes = {};
this.setv(attrs, options);
this.changed = {};
this.initialize.apply(this, arguments);
};
// Attach all inheritable methods to the Model prototype.
object_1.extend(exports.Model.prototype, events_1.Events, {
// A hash of attributes whose current and previous value differ.
changed: null,
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function () { },
// Get the value of an attribute.
getv: function (attr) {
return this.attributes[attr];
},
// Set a hash of model attributes on the object, firing `"change"`. This is
// the core primitive operation of a model, updating the data and notifying
// anyone who needs to know about the change in state. The heart of the beast.
setv: function (key, val, options) {
if (key == null)
return this;
// Handle both `"key", value` and `{key: value}` -style arguments.
var attrs;
if (typeof key === 'object') {
attrs = key;
options = val;
}
else {
(attrs = {})[key] = val;
}
options || (options = {});
// Extract attributes and options.
var silent = options.silent;
var changes = [];
var changing = this._changing;
this._changing = true;
if (!changing) {
this._previousAttributes = object_1.clone(this.attributes);
this.changed = {};
}
var current = this.attributes;
var changed = this.changed;
var prev = this._previousAttributes;
// For each `set` attribute, update or delete the current value.
for (var attr in attrs) {
val = attrs[attr];
if (!eq_1.isEqual(current[attr], val))
changes.push(attr);
if (!eq_1.isEqual(prev[attr], val)) {
changed[attr] = val;
}
else {
delete changed[attr];
}
current[attr] = val;
}
// Trigger all relevant attribute changes.
if (!silent) {
if (changes.length)
this._pending = true;
for (var i = 0; i < changes.length; i++) {
this.trigger('change:' + changes[i], this, current[changes[i]]);
}
}
// You might be wondering why there's a `while` loop here. Changes can
// be recursively nested within `"change"` events.
if (changing)
return this;
if (!silent) {
while (this._pending) {
this._pending = false;
this.trigger('change', this);
}
}
this._pending = false;
this._changing = false;
return this;
},
destroy: function () {
this.stopListening();
this.trigger('destroy', this);
},
// Create a new model with identical attributes to this one.
clone: function () {
return new this.constructor(this.attributes);
}
});
// Backbone.View
// -------------
// Backbone Views are almost more convention than they are actual code. A View
// is simply a JavaScript object that represents a logical chunk of UI in the
// DOM. This might be a single item, an entire list, a sidebar or panel, or
// even the surrounding frame which wraps your whole app. Defining a chunk of
// UI as a **View** allows you to define your DOM events declaratively, without
// having to worry about render order ... and makes it easy for the view to
// react to specific changes in the state of your models.
// Creating a Backbone.View creates its initial element outside of the DOM,
// if an existing element is not provided...
exports.View = function (options) {
options = options || {};
this.model = options.model;
this.id = options.id;
this.el = options.el;
this._ensureElement();
this.initialize(options);
};
// Set up all inheritable **Backbone.View** properties and methods.
object_1.extend(exports.View.prototype, events_1.Events, {
// The default `tagName` of a View's element is `"div"`.
tagName: 'div',
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function (options) { },
// **render** is the core function that your view should override, in order
// to populate its element (`this.el`), with the appropriate HTML. The
// convention is for **render** to always return `this`.
render: function () {
return this;
},
// Remove this view by taking the element out of the DOM, and removing any
// applicable Backbone.Events listeners.
remove: function () {
this._removeElement();
this.stopListening();
return this;
},
// Remove this view's element from the document and all event listeners
// attached to it. Exposed for subclasses using an alternative DOM
// manipulation API.
_removeElement: function () {
var parent = this.el.parentNode;
if (parent != null) {
parent.removeChild(this.el);
}
},
setElement: function (element) {
this._setElement(element);
return this;
},
// Creates the `this.el`.
_setElement: function (el) {
this.el = el;
},
// Produces a DOM element to be assigned to your view. Exposed for
// subclasses using an alternative DOM manipulation API.
_createElement: function (tagName) {
return document.createElement(tagName);
},
// Ensure that the View has a DOM element to render into.
// If `this.el` is a string, pass it through `$()`, take the first
// matching element, and re-assign it to `el`. Otherwise, create
// an element from the `id`, `className` and `tagName` properties.
_ensureElement: function () {
if (!this.el) {
this.setElement(this._createElement(this.tagName));
if (this.id) {
this.el.setAttribute('id', this.id);
}
if (this.className) {
this.el.setAttribute('class', this.className);
}
}
else {
this.setElement(this.el);
}
}
});
exports.Model.getter = exports.View.getter = function (name, get) {
Object.defineProperty(this.prototype, name, { get: get });
};
exports.Model.getters = exports.View.getters = function (specs) {
for (var name in specs) {
this.getter(name, specs[name]);
}
};
},{"./events":"core/events","./util/eq":"core/util/eq","./util/object":"core/util/object"}],"core/bokeh_events":[function(require,module,exports){
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var logging_1 = require("./logging");
var object_1 = require("./util/object");
var event_classes = {};
function register_event_class(event_name) {
return function (event_cls) {
event_cls.prototype.event_name = event_name;
event_classes[event_name] = event_cls;
};
}
exports.register_event_class = register_event_class;
function register_with_event(event_cls) {
var models = [];
for (var _i = 1; _i < arguments.length; _i++) {
models[_i - 1] = arguments[_i];
}
var applicable_models = event_cls.prototype.applicable_models.concat(models);
event_cls.prototype.applicable_models = applicable_models;
}
exports.register_with_event = register_with_event;
var BokehEvent = (function () {
function BokehEvent(options) {
if (options === void 0) { options = {}; }
this._options = options;
if (options.model_id) {
this.model_id = options.model_id;
}
}
BokehEvent.prototype.set_model_id = function (id) {
this._options.model_id = id;
this.model_id = id;
return this;
};
BokehEvent.prototype.is_applicable_to = function (obj) {
return this.applicable_models.some(function (model) { return obj instanceof model; });
};
BokehEvent.event_class = function (e) {
// Given an event with a type attribute matching the event_name,
// return the appropriate BokehEvent class
if (e.type) {
return event_classes[e.type];
}
else {
logging_1.logger.warn('BokehEvent.event_class required events with a string type attribute');
}
};
BokehEvent.prototype.toJSON = function () {
return {
event_name: this.event_name,
event_values: object_1.clone(this._options),
};
};
BokehEvent.prototype._customize_event = function (model) {
return this;
};
return BokehEvent;
}());
exports.BokehEvent = BokehEvent;
BokehEvent.prototype.applicable_models = [];
var ButtonClick = (function (_super) {
__extends(ButtonClick, _super);
function ButtonClick() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ButtonClick;
}(BokehEvent));
ButtonClick = __decorate([
register_event_class("button_click")
], ButtonClick);
exports.ButtonClick = ButtonClick;
// A UIEvent is an event originating on a PlotCanvas this includes
// DOM events such as keystrokes as well as hammer events and LOD events.
var UIEvent = (function (_super) {
__extends(UIEvent, _super);
function UIEvent() {
return _super !== null && _super.apply(this, arguments) || this;
}
return UIEvent;
}(BokehEvent));
exports.UIEvent = UIEvent;
var LODStart = (function (_super) {
__extends(LODStart, _super);
function LODStart() {
return _super !== null && _super.apply(this, arguments) || this;
}
return LODStart;
}(UIEvent));
LODStart = __decorate([
register_event_class("lodstart")
], LODStart);
exports.LODStart = LODStart;
var LODEnd = (function (_super) {
__extends(LODEnd, _super);
function LODEnd() {
return _super !== null && _super.apply(this, arguments) || this;
}
return LODEnd;
}(UIEvent));
LODEnd = __decorate([
register_event_class("lodend")
], LODEnd);
exports.LODEnd = LODEnd;
var PointEvent = (function (_super) {
__extends(PointEvent, _super);
function PointEvent(options) {
var _this = _super.call(this, options) || this;
_this.sx = options.sx;
_this.sy = options.sy;
_this.x = null;
_this.y = null;
return _this;
}
PointEvent.from_event = function (e, model_id) {
if (model_id === void 0) { model_id = null; }
return new this({ sx: e.bokeh['sx'], sy: e.bokeh['sy'], model_id: model_id });
};
PointEvent.prototype._customize_event = function (plot) {
var xmapper = plot.plot_canvas.frame.x_mappers['default'];
var ymapper = plot.plot_canvas.frame.y_mappers['default'];
this.x = xmapper.map_from_target(plot.plot_canvas.canvas.sx_to_vx(this.sx));
this.y = ymapper.map_from_target(plot.plot_canvas.canvas.sy_to_vy(this.sy));
this._options['x'] = this.x;
this._options['y'] = this.y;
return this;
};
return PointEvent;
}(UIEvent));
exports.PointEvent = PointEvent;
var Pan = (function (_super) {
__extends(Pan, _super);
function Pan(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options) || this;
_this.delta_x = options.delta_x;
_this.delta_y = options.delta_y;
return _this;
}
Pan.from_event = function (e, model_id) {
if (model_id === void 0) { model_id = null; }
return new this({
sx: e.bokeh['sx'],
sy: e.bokeh['sy'],
delta_x: e.deltaX,
delta_y: e.deltaY,
direction: e.direction,
model_id: model_id
});
};
return Pan;
}(PointEvent));
Pan = __decorate([
register_event_class("pan")
], Pan);
exports.Pan = Pan;
var Pinch = (function (_super) {
__extends(Pinch, _super);
function Pinch(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options) || this;
_this.scale = options.scale;
return _this;
}
Pinch.from_event = function (e, model_id) {
if (model_id === void 0) { model_id = null; }
return new this({
sx: e.bokeh['sx'],
sy: e.bokeh['sy'],
scale: e.scale,
model_id: model_id,
});
};
return Pinch;
}(PointEvent));
Pinch = __decorate([
register_event_class("pinch")
], Pinch);
exports.Pinch = Pinch;
var MouseWheel = (function (_super) {
__extends(MouseWheel, _super);
function MouseWheel(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options) || this;
_this.delta = options.delta;
return _this;
}
MouseWheel.from_event = function (e, model_id) {
if (model_id === void 0) { model_id = null; }
return new this({
sx: e.bokeh['sx'],
sy: e.bokeh['sy'],
delta: e.delta,
model_id: model_id,
});
};
return MouseWheel;
}(PointEvent));
MouseWheel = __decorate([
register_event_class("wheel")
], MouseWheel);
exports.MouseWheel = MouseWheel;
var MouseMove = (function (_super) {
__extends(MouseMove, _super);
function MouseMove() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MouseMove;
}(PointEvent));
MouseMove = __decorate([
register_event_class("mousemove")
], MouseMove);
exports.MouseMove = MouseMove;
var MouseEnter = (function (_super) {
__extends(MouseEnter, _super);
function MouseEnter() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MouseEnter;
}(PointEvent));
MouseEnter = __decorate([
register_event_class("mouseenter")
], MouseEnter);
exports.MouseEnter = MouseEnter;
var MouseLeave = (function (_super) {
__extends(MouseLeave, _super);
function MouseLeave() {
return _super !== null && _super.apply(this, arguments) || this;
}
return MouseLeave;
}(PointEvent));
MouseLeave = __decorate([
register_event_class("mouseleave")
], MouseLeave);
exports.MouseLeave = MouseLeave;
var Tap = (function (_super) {
__extends(Tap, _super);
function Tap() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Tap;
}(PointEvent));
Tap = __decorate([
register_event_class("tap")
], Tap);
exports.Tap = Tap;
var DoubleTap = (function (_super) {
__extends(DoubleTap, _super);
function DoubleTap() {
return _super !== null && _super.apply(this, arguments) || this;
}
return DoubleTap;
}(PointEvent));
DoubleTap = __decorate([
register_event_class("doubletap")
], DoubleTap);
exports.DoubleTap = DoubleTap;
var Press = (function (_super) {
__extends(Press, _super);
function Press() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Press;
}(PointEvent));
Press = __decorate([
register_event_class("press")
], Press);
exports.Press = Press;
var PanStart = (function (_super) {
__extends(PanStart, _super);
function PanStart() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PanStart;
}(PointEvent));
PanStart = __decorate([
register_event_class("panstart")
], PanStart);
exports.PanStart = PanStart;
var PanEnd = (function (_super) {
__extends(PanEnd, _super);
function PanEnd() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PanEnd;
}(PointEvent));
PanEnd = __decorate([
register_event_class("panend")
], PanEnd);
exports.PanEnd = PanEnd;
var PinchStart = (function (_super) {
__extends(PinchStart, _super);
function PinchStart() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PinchStart;
}(PointEvent));
PinchStart = __decorate([
register_event_class("pinchstart")
], PinchStart);
exports.PinchStart = PinchStart;
var PinchEnd = (function (_super) {
__extends(PinchEnd, _super);
function PinchEnd() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PinchEnd;
}(PointEvent));
PinchEnd = __decorate([
register_event_class("pinchend")
], PinchEnd);
exports.PinchEnd = PinchEnd;
},{"./logging":"core/logging","./util/object":"core/util/object"}],"core/bokeh_view":[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var extend = function (child, parent) { for (var key in parent) {
if (hasProp.call(parent, key))
child[key] = parent[key];
} function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty;
var Backbone = require("./backbone");
var string_1 = require("./util/string");
exports.BokehView = (function (superClass) {
extend(BokehView, superClass);
function BokehView() {
return BokehView.__super__.constructor.apply(this, arguments);
}
BokehView.prototype.initialize = function (options) {
if (options.id == null) {
return this.id = string_1.uniqueId('BokehView');
}
};
BokehView.prototype.toString = function () {
return this.model.type + "View(" + this.id + ")";
};
BokehView.prototype.bind_bokeh_events = function () { };
BokehView.prototype.remove = function () {
this.trigger('remove', this);
return BokehView.__super__.remove.call(this);
};
return BokehView;
})(Backbone.View);
},{"./backbone":"core/backbone","./util/string":"core/util/string"}],"core/build_views":[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var array_1 = require("./util/array");
var object_1 = require("./util/object");
exports.build_views = function (view_storage, view_models, options, view_types) {
var cls, created_views, i, i_model, j, key, len, len1, model, newmodels, ref, to_remove, view, view_options;
if (view_types == null) {
view_types = [];
}
created_views = [];
newmodels = view_models.filter(function (x) {
return view_storage[x.id] == null;
});
for (i_model = i = 0, len = newmodels.length; i < len; i_model = ++i) {
model = newmodels[i_model];
cls = (ref = view_types[i_model]) != null ? ref : model.default_view;
view_options = object_1.extend({
model: model
}, options);
view_storage[model.id] = view = new cls(view_options);
created_views.push(view);
}
to_remove = array_1.difference(Object.keys(view_storage), (function () {
var j, len1, results;
results = [];
for (j = 0, len1 = view_models.length; j < len1; j++) {
view = view_models[j];
results.push(view.id);
}
return results;
})());
for (j = 0, len1 = to_remove.length; j < len1; j++) {
key = to_remove[j];
view_storage[key].remove();
delete view_storage[key];
}
return created_views;
};
},{"./util/array":"core/util/array","./util/object":"core/util/object"}],"core/dom":[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("./util/types");
var _createElement = function (tag) { return function (attrs) {
if (attrs === void 0) { attrs = {}; }
var children = [];
for (var _i = 1; _i < arguments.length; _i++) {
children[_i - 1] = arguments[_i];
}
var element;
if (tag === "fragment") {
// XXX: this is wrong, but the the common super type of DocumentFragment and HTMLElement is
// Node, which doesn't support classList, style, etc. attributes.
element = document.createDocumentFragment();
}
else {
element = document.createElement(tag);
for (var attr in attrs) {
var value = attrs[attr];
if (value == null || types_1.isBoolean(value) && !value)
continue;
if (attr === "class" && types_1.isArray(value)) {
for (var _a = 0, _b = value; _a < _b.length; _a++) {
var cls = _b[_a];
if (cls != null)
element.classList.add(cls);
}
continue;
}
if (attr === "style" && types_1.isObject(value)) {
for (var prop in value) {
element.style[prop] = value[prop];
}
continue;
}
element.setAttribute(attr, value);
}
}
function append(child) {
if (child instanceof HTMLElement)
element.appendChild(child);
else if (types_1.isString(child))
element.appendChild(document.createTextNode(child));
else if (child != null && child !== false)
throw new Error("expected an HTMLElement, string, false or null, got " + JSON.stringify(child));
}
for (var _c = 0, children_1 = children; _c < children_1.length; _c++) {
var child = children_1[_c];
if (types_1.isArray(child)) {
for (var _d = 0, child_1 = child; _d < child_1.length; _d++) {
var _child = child_1[_d];
append(_child);
}
}
else
append(child);
}
return element;
}; };
function createElement(tag, attrs) {
var children = [];
for (var _i = 2; _i < arguments.length; _i++) {
children[_i - 2] = arguments[_i];
}
return _createElement(tag).apply(void 0, [attrs].concat(children));
}
exports.createElement = createElement;
exports.div = _createElement("div"), exports.span = _createElement("span"), exports.link = _createElement("link"), exports.style = _createElement("style"), exports.a = _createElement("a"), exports.p = _createElement("p"), exports.pre = _createElement("pre"), exports.input = _createElement("input"), exports.label = _createElement("label"), exports.canvas = _createElement("canvas"), exports.ul = _createElement("ul"), exports.ol = _createElement("ol"), exports.li = _createElement("li");
function show(element) {
element.style.display = "";
}
exports.show = show;
function hide(element) {
element.style.display = "none";
}
exports.hide = hide;
function empty(element) {
var child;
while (child = element.firstChild) {
element.removeChild(child);
}
}
exports.empty = empty;
function position(element) {
return {
top: element.offsetTop,
left: element.offsetLeft,
};
}
exports.position = position;
function offset(element) {
var rect = element.getBoundingClientRect();
return {
top: rect.top + window.pageYOffset - document.documentElement.clientTop,
left: rect.left + window.pageXOffset - document.documentElement.clientLeft,
};
}
exports.offset = offset;
function replaceWith(element, replacement) {
var parent = element.parentNode;
if (parent != null) {
parent.replaceChild(replacement, element);
}
}
exports.replaceWith = replaceWith;
},{"./util/types":"core/util/types"}],"core/enums":[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AngleUnits = ["deg", "rad"];
exports.Dimension = ["width", "height"];
exports.Dimensions = ["width", "height", "both"];
exports.Direction = ["clock", "anticlock"];
exports.FontStyle = ["normal", "italic", "bold"];
exports.LatLon = ["lat", "lon"];
exports.LineCap = ["butt", "round", "square"];
exports.LineJoin = ["miter", "round", "bevel"];
exports.Location = ["above", "below", "left", "right"];
exports.LegendLocation = ["top_left", "top_center", "top_right", "center_left", "center", "center_right", "bottom_left", "bottom_center", "bottom_right"];
exports.Orientation = ["vertical", "horizontal"];
exports