From 75febea669c0c407397797ff9b8a30cf0e7c9bca Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sun, 27 Jul 2014 11:32:38 -0700 Subject: [PATCH 01/33] Select and drag text labels with nodes. Better rotation. fixes #61 --- escher/js/src/Behavior.js | 372 ++++++++++++--------- escher/js/src/Brush.js | 17 +- escher/js/src/Builder.js | 15 +- escher/js/src/Input.js | 2 +- escher/js/src/Map.js | 93 ++++-- escher/js/src/draw.js | 40 +-- escher/lib/escher.1.0.0b2.js | 537 +++++++++++++++++++------------ escher/lib/escher.1.0.0b2.min.js | 2 +- 8 files changed, 666 insertions(+), 412 deletions(-) diff --git a/escher/js/src/Behavior.js b/escher/js/src/Behavior.js index acd729d3..3819f3c7 100644 --- a/escher/js/src/Behavior.js +++ b/escher/js/src/Behavior.js @@ -4,10 +4,22 @@ define(["utils", "build"], function(utils, build) { Has the following attributes: - Behavior.node_click - Behavior.node_drag - Behavior.bezier_drag - Behavior.label_drag + Behavior.rotation_drag: + + Behavior.selectable_click: + + Behavior.node_mouseover: + + Behavior.node_mouseout: + + Behavior.selectable_drag: + + Behavior.bezier_drag: + + Behavior.reaction_label_drag: + + Behavior.node_label_drag: + */ var Behavior = utils.make_class(); @@ -15,16 +27,15 @@ define(["utils", "build"], function(utils, build) { toggle_rotation_mode: toggle_rotation_mode, turn_everything_on: turn_everything_on, turn_everything_off: turn_everything_off, - toggle_node_click: toggle_node_click, - toggle_node_drag: toggle_node_drag, - toggle_text_label_click: toggle_text_label_click, + toggle_selectable_click: toggle_selectable_click, + toggle_selectable_drag: toggle_selectable_drag, toggle_label_drag: toggle_label_drag, - get_node_drag: get_node_drag, + get_selectable_drag: get_selectable_drag, get_bezier_drag: get_bezier_drag, get_reaction_label_drag: get_reaction_label_drag, get_node_label_drag: get_node_label_drag, - get_text_label_drag: get_text_label_drag, - get_generic_drag: get_generic_drag }; + get_generic_drag: get_generic_drag, + get_generic_angular_drag: get_generic_angular_drag }; return Behavior; @@ -41,33 +52,29 @@ define(["utils", "build"], function(utils, build) { this.rotation_drag = d3.behavior.drag(); // init empty - this.node_click = null; + this.selectable_click = null; this.node_mouseover = null; this.node_mouseout = null; - this.node_drag = this.empty_behavior; + this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; - this.text_label_click = null; - this.text_label_drag = this.empty_behavior; this.turn_everything_on(); } function turn_everything_on() { /** Toggle everything except rotation mode. */ - this.toggle_node_click(true); - this.toggle_node_drag(true); - this.toggle_text_label_click(true); + this.toggle_selectable_click(true); + this.toggle_selectable_drag(true); this.toggle_label_drag(true); } function turn_everything_off() { /** Toggle everything except rotation mode. */ - this.toggle_node_click(false); - this.toggle_node_drag(false); - this.toggle_text_label_click(false); + this.toggle_selectable_click(false); + this.toggle_selectable_drag(false); this.toggle_label_drag(false); } @@ -107,43 +114,41 @@ define(["utils", "build"], function(utils, build) { // silence other listeners d3.event.sourceEvent.stopPropagation(); }, - drag_fn = function(d, displacement, total_displacement, location) { - var angle = utils.angle_for_event(displacement, - location, - this.center); + drag_fn = function(d, angle, total_angle, center) { var updated = build.rotate_nodes(selected_nodes, reactions, - angle, this.center); + angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); - }.bind(this), + }, end_fn = function(d) {}, - undo_fn = function(d, displacement, location) { + undo_fn = function(d, total_angle, center) { // undo - var total_angle = utils.angle_for_event(displacement, - location, - this.center); - var these_nodes = {}; - selected_node_ids.forEach(function(id) { these_nodes[id] = nodes[id]; }); + selected_node_ids.forEach(function(id) { + these_nodes[id] = nodes[id]; + }); var updated = build.rotate_nodes(these_nodes, reactions, - -total_angle, utils.clone(this.center)); + -total_angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); - }.bind(this), - redo_fn = function(d, displacement, location) { + }, + redo_fn = function(d, total_angle, center) { // redo - var total_angle = utils.angle_for_event(displacement, - location, - this.center), - these_nodes = {}; - selected_node_ids.forEach(function(id) { these_nodes[id] = nodes[id]; }); + var these_nodes = {}; + selected_node_ids.forEach(function(id) { + these_nodes[id] = nodes[id]; + }); var updated = build.rotate_nodes(these_nodes, reactions, - total_angle, utils.clone(this.center)); + total_angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); + }, + center_fn = function() { + return this.center; }.bind(this); - this.rotation_drag = this.get_generic_drag(start_fn, drag_fn, end_fn, - undo_fn, redo_fn, this.map.sel); + this.rotation_drag = this.get_generic_angular_drag(start_fn, drag_fn, end_fn, + undo_fn, redo_fn, center_fn, + this.map.sel); selection_background.call(this.rotation_drag); @@ -206,17 +211,18 @@ define(["utils", "build"], function(utils, build) { } } - function toggle_node_click(on_off) { + function toggle_selectable_click(on_off) { /** With no argument, toggle the node click on or off. Pass in a boolean argument to set the on/off state. */ - if (on_off===undefined) on_off = this.node_click==null; + if (on_off===undefined) on_off = this.selectable_click==null; if (on_off) { var map = this.map; - this.node_click = function(d) { - map.select_metabolite(this, d); + this.selectable_click = function(d) { + if (d3.event.defaultPrevented) return; // click suppressed + map.select_selectable(this, d); d3.event.stopPropagation(); }; this.node_mouseover = function(d) { @@ -228,42 +234,26 @@ define(["utils", "build"], function(utils, build) { d3.select(this).style('stroke-width', null); }; } else { - this.node_click = null; + this.selectable_click = null; this.node_mouseover = null; this.node_mouseout = null; this.map.sel.select('#nodes') .selectAll('.node-circle').style('stroke-width', null); } } - function toggle_text_label_click(on_off) { - /** With no argument, toggle the node click on or off. - Pass in a boolean argument to set the on/off state. - - */ - if (on_off===undefined) on_off = this.text_label_click==null; - if (on_off) { - var map = this.map; - this.text_label_click = function(d) { - map.select_text_label(this, d); - d3.event.stopPropagation(); - }; - } else { - this.text_label_click = null; - } - } - function toggle_node_drag(on_off) { + function toggle_selectable_drag(on_off) { /** With no argument, toggle the node drag & bezier drag on or off. Pass in a boolean argument to set the on/off state. */ - if (on_off===undefined) on_off = this.node_drag===this.empty_behavior; + if (on_off===undefined) on_off = this.selectable_drag===this.empty_behavior; if (on_off) { - this.node_drag = this.get_node_drag(this.map, this.undo_stack); + this.selectable_drag = this.get_selectable_drag(this.map, this.undo_stack); this.bezier_drag = this.get_bezier_drag(this.map, this.undo_stack); } else { - this.node_drag = this.empty_behavior; + this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; } } @@ -277,84 +267,125 @@ define(["utils", "build"], function(utils, build) { if (on_off) { this.reaction_label_drag = this.get_reaction_label_drag(this.map); this.node_label_drag = this.get_node_label_drag(this.map); - this.text_label_drag = this.get_text_label_drag(this.map); } else { this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; - this.text_label_drag = this.empty_behavior; } } - function get_node_drag(map, undo_stack) { + function get_selectable_drag(map, undo_stack) { + /** Drag the selected nodes and text labels. + + */ + // define some variables var behavior = d3.behavior.drag(), + the_timeout = null, total_displacement = null, - nodes_to_drag = null, + // for nodes + node_ids_to_drag = null, reaction_ids = null, - the_timeout = null; + // for text labels + text_label_ids_to_drag = null, + move_label = function(text_label_id, displacement) { + var text_label = map.text_labels[text_label_id]; + text_label.x = text_label.x + displacement.x; + text_label.y = text_label.y + displacement.y; + }; behavior.on("dragstart", function () { - // Note that dragstart is called even for a click event - var data = this.parentNode.__data__, - bigg_id = data.bigg_id, - node_group = this.parentNode; // silence other listeners - d3.event.sourceEvent.stopPropagation(); + d3.event.sourceEvent.stopPropagation(); console.log('dragstart'); // remember the total displacement for later - total_displacement = {}; - // Move element to back (for the next step to work). Wait 200ms - // before making the move, becuase otherwise the element will be - // deleted before the click event gets called, and selection - // will stop working. - the_timeout = window.setTimeout(function() { - node_group.parentNode.insertBefore(node_group,node_group.parentNode.firstChild); - }, 200); - // prepare to combine metabolites - map.sel.selectAll('.metabolite-circle') - .on('mouseover.combine', function(d) { - if (d.bigg_id==bigg_id && d.node_id!=data.node_id) { - d3.select(this).style('stroke-width', String(12)+'px') - .classed('node-to-combine', true); - } - }).on('mouseout.combine', function(d) { - if (d.bigg_id==bigg_id) { - map.sel.selectAll('.node-to-combine').style('stroke-width', String(2)+'px') - .classed('node-to-combine', false); - } - }); + // total_displacement = {}; + total_displacement = {x: 0, y: 0}; + + // If a text label is selected, the rest is not necessary + if (d3.select(this).attr('class').indexOf('text-label')==-1) { + // Note that dragstart is called even for a click event + var data = this.parentNode.__data__, + bigg_id = data.bigg_id, + node_group = this.parentNode; + // Move element to back (for the next step to work). Wait 200ms + // before making the move, becuase otherwise the element will be + // deleted before the click event gets called, and selection + // will stop working. + the_timeout = window.setTimeout(function() { + node_group.parentNode.insertBefore(node_group,node_group.parentNode.firstChild); + }, 200); + // prepare to combine metabolites + map.sel.selectAll('.metabolite-circle') + .on('mouseover.combine', function(d) { + if (d.bigg_id==bigg_id && d.node_id!=data.node_id) { + d3.select(this).style('stroke-width', String(12)+'px') + .classed('node-to-combine', true); + } + }).on('mouseout.combine', function(d) { + if (d.bigg_id==bigg_id) { + map.sel.selectAll('.node-to-combine').style('stroke-width', String(2)+'px') + .classed('node-to-combine', false); + } + }); + } }); behavior.on("drag", function() { - var grabbed_id = this.parentNode.__data__.node_id, - selected_ids = map.get_selected_node_ids(); - nodes_to_drag = []; - // choose the nodes to drag - if (selected_ids.indexOf(grabbed_id)==-1) { - nodes_to_drag.push(grabbed_id); + // get the grabbed id + var grabbed = {}; + if (d3.select(this).attr('class').indexOf('text-label')==-1) { + // if it is a node + grabbed['type'] = 'node'; + grabbed['id'] = this.parentNode.__data__.node_id; + } else { + // if it is a text label + grabbed['type'] = 'text-label'; + grabbed['id'] = this.__data__.text_label_id; + } + + var selected_node_ids = map.get_selected_node_ids(), + selected_text_label_ids = map.get_selected_text_label_ids(); + node_ids_to_drag = []; text_label_ids_to_drag = []; + // choose the nodes and text labels to drag + if (grabbed['type']=='node' && + selected_node_ids.indexOf(grabbed['id'])==-1) { + node_ids_to_drag.push(grabbed['id']); + } else if (grabbed['type']=='text-label' && + selected_text_label_ids.indexOf(grabbed['id'])==-1) { + text_label_ids_to_drag.push(grabbed['id']); } else { - nodes_to_drag = selected_ids; + node_ids_to_drag = selected_node_ids; + text_label_ids_to_drag = selected_text_label_ids; } reaction_ids = []; - nodes_to_drag.forEach(function(node_id) { + var displacement = { x: d3.event.dx, + y: d3.event.dy }; + total_displacement = utils.c_plus_c(total_displacement, displacement); + node_ids_to_drag.forEach(function(node_id) { // update data var node = map.nodes[node_id], - displacement = { x: d3.event.dx, - y: d3.event.dy }, updated = build.move_node_and_dependents(node, node_id, map.reactions, displacement); reaction_ids = utils.unique_concat([reaction_ids, updated.reaction_ids]); // remember the displacements - if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; - total_displacement[node_id] = utils.c_plus_c(total_displacement[node_id], displacement); + // if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; + // total_displacement[node_id] = utils.c_plus_c(total_displacement[node_id], displacement); + }); + text_label_ids_to_drag.forEach(function(text_label_id) { + move_label(text_label_id, displacement); + // remember the displacements + // if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; + // total_displacement[node_id] = utils.c_plus_c(total_displacement[node_id], displacement); }); // draw - map.draw_these_nodes(nodes_to_drag); + map.draw_these_nodes(node_ids_to_drag); map.draw_these_reactions(reaction_ids); + map.draw_these_text_labels(text_label_ids_to_drag); }); behavior.on("dragend", function() { - if (nodes_to_drag===null) { + if (node_ids_to_drag===null) { // Dragend can be called when drag has not been called. In this, // case, do nothing. total_displacement = null; - nodes_to_drag = null; + node_ids_to_drag = null; + text_label_ids_to_drag = null; reaction_ids = null; the_timeout = null; return; @@ -408,26 +439,36 @@ define(["utils", "build"], function(utils, build) { var saved_displacement = utils.clone(total_displacement), // BUG TODO this variable disappears! // Happens sometimes when you drag a node, then delete it, then undo twice - saved_node_ids = utils.clone(nodes_to_drag), + saved_node_ids = utils.clone(node_ids_to_drag), + saved_text_label_ids = utils.clone(text_label_ids_to_drag), saved_reaction_ids = utils.clone(reaction_ids); undo_stack.push(function() { // undo saved_node_ids.forEach(function(node_id) { var node = map.nodes[node_id]; build.move_node_and_dependents(node, node_id, map.reactions, - utils.c_times_scalar(saved_displacement[node_id], -1)); + utils.c_times_scalar(saved_displacement, -1)); + }); + saved_text_label_ids.forEach(function(text_label_id) { + move_label(text_label_id, + utils.c_times_scalar(saved_displacement, -1)); }); map.draw_these_nodes(saved_node_ids); map.draw_these_reactions(saved_reaction_ids); + map.draw_these_text_labels(saved_text_label_ids); }, function () { // redo saved_node_ids.forEach(function(node_id) { var node = map.nodes[node_id]; build.move_node_and_dependents(node, node_id, map.reactions, - saved_displacement[node_id]); + saved_displacement); + }); + saved_text_label_ids.forEach(function(text_label_id) { + move_label(text_label_id, saved_displacement); }); map.draw_these_nodes(saved_node_ids); map.draw_these_reactions(saved_reaction_ids); + map.draw_these_text_labels(saved_text_label_ids); }); } @@ -441,7 +482,8 @@ define(["utils", "build"], function(utils, build) { // clear the shared variables total_displacement = null; - nodes_to_drag = null; + node_ids_to_drag = null; + text_label_ids_to_drag = null; reaction_ids = null; the_timeout = null; }); @@ -551,32 +593,7 @@ define(["utils", "build"], function(utils, build) { return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, this.map.sel); } - function get_text_label_drag(map) { - var move_label = function(text_label_id, displacement) { - var text_label = map.text_labels[text_label_id]; - text_label.x = text_label.x + displacement.x; - text_label.y = text_label.y + displacement.y; - }, - start_fn = function(d) { - }, - drag_fn = function(d, displacement, total_displacement) { - // draw - move_label(d.text_label_id, displacement); - map.draw_these_text_labels([d.text_label_id]); - }, - end_fn = function(d) { - }, - undo_fn = function(d, displacement) { - move_label(d.text_label_id, utils.c_times_scalar(displacement, -1)); - map.draw_these_text_labels([d.text_label_id]); - }, - redo_fn = function(d, displacement) { - move_label(d.text_label_id, displacement); - map.draw_these_text_labels([d.text_label_id]); - }; - return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, - redo_fn, this.map.sel); - } + function get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, relative_to_selection) { /** Make a generic drag behavior, with undo/redo. @@ -637,4 +654,71 @@ define(["utils", "build"], function(utils, build) { }); return behavior; } + + function get_generic_angular_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, + get_center, relative_to_selection) { + /** Make a generic drag behavior, with undo/redo. Supplies angles in + place of displacements. + + start_fn: function(d) Called at dragstart. + + drag_fn: function(d, displacement, total_displacement) Called during + drag. + + end_fn: + + undo_fn: + + redo_fn: + + get_center: + + relative_to_selection: a d3 selection that the locations are calculated against. + + */ + + // define some variables + var behavior = d3.behavior.drag(), + total_angle, + undo_stack = this.undo_stack, + rel = relative_to_selection.node(); + + behavior.on("dragstart", function (d) { + // silence other listeners + d3.event.sourceEvent.stopPropagation(); + total_angle = 0; + start_fn(d); + }); + behavior.on("drag", function(d) { + // update data + var displacement = { x: d3.event.dx, + y: d3.event.dy }, + location = { x: d3.mouse(rel)[0], + y: d3.mouse(rel)[1] }, + center = get_center(), + angle = utils.angle_for_event(displacement, + location, + center); + // remember the displacement + total_angle = total_angle + angle; + drag_fn(d, angle, total_angle, center); + }); + behavior.on("dragend", function(d) { + // add to undo/redo stack + // remember the displacement, dragged nodes, and reactions + var saved_d = utils.clone(d), + saved_angle = total_angle, + saved_center = utils.clone(get_center()); + + undo_stack.push(function() { + // undo + undo_fn(saved_d, saved_angle, saved_center); + }, function () { + // redo + redo_fn(saved_d, saved_angle, saved_center); + }); + end_fn(d); + }); + return behavior; + } }); diff --git a/escher/js/src/Brush.js b/escher/js/src/Brush.js index 360e307b..5fedfd9b 100644 --- a/escher/js/src/Brush.js +++ b/escher/js/src/Brush.js @@ -1,7 +1,14 @@ define(["utils"], function(utils) { /** Define a brush to select elements in a map. - Brush(selection, is_enabled, map, insert_after) + Arguments + --------- + + selection: A d3 selection to place the brush in. + + is_enabled: Whether to turn the brush on. + + map: An instance of escher.Map. insert_after: A d3 selector string to choose the svg element that the brush will be inserted after. Often a canvas element (e.g. '.canvas-group'). @@ -47,7 +54,7 @@ define(["utils"], function(utils) { } function setup_selection_brush() { var selection = this.brush_sel, - nodes_selection = this.map.sel.select('#nodes'), + selectable_selection = this.map.sel.selectAll('#nodes,#text-labels'), size_and_location = this.map.canvas.size_and_location(), width = size_and_location.width, height = size_and_location.height, @@ -62,10 +69,12 @@ define(["utils"], function(utils) { selection; if (shift_key_on) { // when shift is pressed, ignore the currently selected nodes - selection = nodes_selection.selectAll('.node:not(.selected)'); + selection = selectable_selection + .selectAll('.node,.text-label:not(.selected)'); } else { // otherwise, brush all nodes - selection = nodes_selection.selectAll('.node'); + selection = selectable_selection + .selectAll('.node,.text-label'); } selection.classed("selected", function(d) { var sx = d.x, sy = d.y; diff --git a/escher/js/src/Builder.js b/escher/js/src/Builder.js index b98a5c12..126da44f 100644 --- a/escher/js/src/Builder.js +++ b/escher/js/src/Builder.js @@ -129,7 +129,7 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba */ // Begin with some definitions - var node_click_enabled = true, + var selectable_click_enabled = true, shift_key_on = false; // set up this callback manager @@ -274,12 +274,13 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba this.map.canvas.toggle_resize(mode=='zoom' || mode=='brush'); // behavior this.map.behavior.toggle_rotation_mode(mode=='rotate'); - this.map.behavior.toggle_node_click(mode=='build' || mode=='brush'); - this.map.behavior.toggle_node_drag(mode=='brush'); - this.map.behavior.toggle_text_label_click(mode=='brush'); + this.map.behavior.toggle_selectable_click(mode=='build' || mode=='brush' || mode=='rotate'); + this.map.behavior.toggle_selectable_drag(mode=='brush' || mode=='rotate'); this.map.behavior.toggle_label_drag(mode=='brush'); if (mode=='view') this.map.select_none(); + if (mode=='rotate') + this.map.deselect_text_labels(); this.map.draw_everything(); } function view_mode() { @@ -563,13 +564,13 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba brush.toggle(false); was_enabled.zoom = zoom_container.zoom_on; zoom_container.toggle_zoom(false); - was_enabled.node_click = map.behavior.node_click!=null; - map.behavior.toggle_node_click(false); + was_enabled.selectable_click = map.behavior.selectable_click!=null; + map.behavior.toggle_selectable_click(false); }); map.callback_manager.set('end_rotation', function() { brush.toggle(was_enabled.brush); zoom_container.toggle_zoom(was_enabled.zoom); - map.behavior.toggle_node_click(was_enabled.node_click); + map.behavior.toggle_selectable_click(was_enabled.selectable_click); was_enabled = {}; }); } diff --git a/escher/js/src/Input.js b/escher/js/src/Input.js index 60059df7..11fccfe5 100644 --- a/escher/js/src/Input.js +++ b/escher/js/src/Input.js @@ -75,7 +75,7 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", if (this.is_active) this.reload(selected_node, coords, false); this.hide_target(); }.bind(this)); - map.callback_manager.set('select_metabolite.input', function(count, selected_node, coords) { + map.callback_manager.set('select_selectable.input', function(count, selected_node, coords) { this.hide_target(); if (count == 1 && this.is_active && coords) { this.reload(selected_node, coords, false); diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index c8eede09..4c2778b3 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -3,8 +3,28 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan Arguments --------- - selection: A d3 selection for a node to place the map inside. Should be an SVG element. - behavior: A Behavior object which defines the interactivity of the map. + + svg: + + css: + + selection: A d3 selection for a node to place the map inside. + + selection: + + zoom_container: + + settings: + + reaction_data: + + metabolite_data: + + cobra_model: + + canvas_size_and_loc: + + enable_search: */ @@ -29,7 +49,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan clear_map: clear_map, // selection select_none: select_none, - select_metabolite: select_metabolite, + select_selectable: select_selectable, select_metabolite_with_id: select_metabolite_with_id, select_single_node: select_single_node, deselect_nodes: deselect_nodes, @@ -466,14 +486,14 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan defs = this.defs, default_reaction_color = this.default_reaction_color, bezier_drag_behavior = this.behavior.bezier_drag, - node_click_fn = this.behavior.node_click, + node_click_fn = this.behavior.selectable_click, node_mouseover_fn = this.behavior.node_mouseover, node_mouseout_fn = this.behavior.node_mouseout, - node_drag_behavior = this.behavior.node_drag, + node_drag_behavior = this.behavior.selectable_drag, reaction_label_drag = this.behavior.reaction_label_drag, node_label_drag = this.behavior.node_label_drag, - text_label_click = this.behavior.text_label_click, - text_label_drag = this.behavior.text_label_drag, + text_label_click = this.behavior.selectable_click, + text_label_drag = this.behavior.selectable_drag, has_reaction_data = this.has_reaction_data(), reaction_data_styles = this.settings.data_styles['reaction'], has_metabolite_data = this.has_metabolite_data(), @@ -582,10 +602,10 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan var scale = this.scale, reactions = this.reactions, nodes = this.nodes, - node_click_fn = this.behavior.node_click, + node_click_fn = this.behavior.selectable_click, node_mouseover_fn = this.behavior.node_mouseover, node_mouseout_fn = this.behavior.node_mouseout, - node_drag_behavior = this.behavior.node_drag, + node_drag_behavior = this.behavior.selectable_drag, node_label_drag = this.behavior.node_label_drag, metabolite_data_styles = this.settings.data_styles['metabolite'], has_metabolite_data = this.has_metabolite_data(); @@ -623,8 +643,8 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } function draw_these_text_labels(text_label_ids) { var text_labels = this.text_labels, - text_label_click = this.behavior.text_label_click, - text_label_drag = this.behavior.text_label_drag; + text_label_click = this.behavior.selectable_click, + text_label_drag = this.behavior.selectable_drag; // find text labels for text_label_ids var text_label_subset = {}, @@ -841,9 +861,10 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } function select_metabolite_with_id(node_id) { - // deselect all text labels - this.deselect_text_labels(); + /** Select a metabolite with the given id, and turn off the reaction + target. + */ var node_selection = this.sel.select('#nodes').selectAll('.node'), coords, selected_node; @@ -858,27 +879,39 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.sel.selectAll('.start-reaction-target').style('visibility', 'hidden'); this.callback_manager.run('select_metabolite_with_id', selected_node, coords); } - function select_metabolite(sel, d) { - // deselect all text labels - this.deselect_text_labels(); - - var node_selection = this.sel.select('#nodes').selectAll('.node'), - shift_key_on = this.key_manager.held_keys.shift; + function select_selectable(node, d) { + /** Select a metabolite or text label, and manage the shift key. + + */ + var classable_selection = this.sel.selectAll('#nodes,#text-labels') + .selectAll('.node,.text-label'), + shift_key_on = this.key_manager.held_keys.shift, + classable_node; + if (d3.select(node).attr('class').indexOf('text-label') == -1) { + // node + classable_node = node.parentNode; + } else { + // text-label + classable_node = node; + } + // toggle selection if (shift_key_on) { - d3.select(sel.parentNode) - .classed("selected", !d3.select(sel.parentNode).classed("selected")); + d3.select(classable_node) + .classed("selected", !d3.select(classable_node).classed("selected")); + } else { + classable_selection.classed("selected", function(p) { return d === p; }); } - else node_selection.classed("selected", function(p) { return d === p; }); + // run the select_metabolite callback var selected_nodes = this.sel.select('#nodes').selectAll('.selected'), - count = 0, + node_count = 0, coords, selected_node; selected_nodes.each(function(d) { selected_node = d; coords = { x: d.x, y: d.y }; - count++; + node_count++; }); - this.callback_manager.run('select_metabolite', count, selected_node, coords); + this.callback_manager.run('select_selectable', node_count, selected_node, coords); } function select_single_node() { /** Unselect all but one selected node, and return the node. @@ -980,7 +1013,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.extend_nodes(saved_nodes); this.extend_reactions(saved_reactions); - var reactions_to_draw = Object.keys(saved_reactions); + var reaction_ids_to_draw = Object.keys(saved_reactions); saved_segment_objs_w_segments.forEach(function(segment_obj) { var segment = segment_obj.segment; this.reactions[segment_obj.reaction_id] @@ -995,8 +1028,8 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan segment_id: segment_obj.segment_id }); }.bind(this)); - if (reactions_to_draw.indexOf(segment_obj.reaction_id)==-1) - reactions_to_draw.push(segment_obj.reaction_id); + if (reaction_ids_to_draw.indexOf(segment_obj.reaction_id)==-1) + reaction_ids_to_draw.push(segment_obj.reaction_id); }.bind(this)); // apply the reaction and node data @@ -1004,9 +1037,9 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan if (this.has_reaction_data()) { var scale_changed = this.update_reaction_data_domain(); if (scale_changed) this.draw_all_reactions(); - else this.draw_these_reactions(Object.keys(reactions_to_draw)); + else this.draw_these_reactions(reaction_ids_to_draw); } else { - this.draw_these_reactions(Object.keys(reactions_to_draw)); + this.draw_these_reactions(reaction_ids_to_draw); } if (this.has_metabolite_data()) { var scale_changed = this.update_metabolite_data_domain(); diff --git a/escher/js/src/draw.js b/escher/js/src/draw.js index 803423e7..9133984c 100644 --- a/escher/js/src/draw.js +++ b/escher/js/src/draw.js @@ -1,6 +1,6 @@ -"use strict"; +'use strict'; -define(["utils", "data_styles"], function(utils, data_styles) { +define(['utils', 'data_styles'], function(utils, data_styles) { return { create_reaction: create_reaction, update_reaction: update_reaction, create_node: create_node, @@ -26,10 +26,10 @@ define(["utils", "data_styles"], function(utils, data_styles) { function update_membrane(update_selection) { utils.check_undefined(arguments, ['enter_selection']); update_selection - .attr("width", function(d){ return d.width; }) - .attr("height", function(d){ return d.height; }) - .attr("transform", function(d){return "translate("+d.x+","+d.y+")";}) - .style("stroke-width", function(d) { return 10; }) + .attr('width', function(d){ return d.width; }) + .attr('height', function(d){ return d.height; }) + .attr('transform', function(d){return 'translate('+d.x+','+d.y+')';}) + .style('stroke-width', function(d) { return 10; }) .attr('rx', function(d){ return 20; }) .attr('ry', function(d){ return 20; }); } @@ -116,7 +116,7 @@ define(["utils", "data_styles"], function(utils, data_styles) { // update_selection // .attr('d', function(d) { // if (d.x==null || d.y==null || d.source_x==null || d.source_y==null) - // return ""; + // return ''; // return 'M0, 0 '+(d.source_x-d.x)+','+(d.source_y-d.y); // }); // } @@ -132,13 +132,13 @@ define(["utils", "data_styles"], function(utils, data_styles) { sel.append('text') .attr('class', 'reaction-label label') .style('cursor', 'default'); - // .on("mouseover", function(d) { + // .on('mouseover', function(d) { // d3.select(this).style('stroke-width', String(3)+'px'); // d3.select(this.parentNode) // .selectAll('.connect-line') // .attr('visibility', 'visible'); // }) - // .on("mouseout", function(d) { + // .on('mouseout', function(d) { // d3.select(this).style('stroke-width', String(1)+'px'); // d3.select(this.parentNode) // .selectAll('.connect-line') @@ -162,8 +162,8 @@ define(["utils", "data_styles"], function(utils, data_styles) { return t; }).attr('transform', function(d) { return 'translate('+d.label_x+','+d.label_y+')'; - }).style("font-size", function(d) { - return String(30)+"px"; + }).style('font-size', function(d) { + return String(30)+'px'; }) .call(turn_off_drag) .call(label_drag_behavior); @@ -295,7 +295,7 @@ define(["utils", "data_styles"], function(utils, data_styles) { arrowheads.enter().append('path') .classed('arrowhead', true); // update arrowheads - arrowheads.attr("d", function(d) { + arrowheads.attr('d', function(d) { var markerWidth = 20, markerHeight = 13; if (has_reaction_data && reaction_data_styles.indexOf('size')!==-1) { var f = d.data; @@ -371,13 +371,13 @@ define(["utils", "data_styles"], function(utils, data_styles) { .attr('class', function(d) { return 'bezier bezier'+d.bezier; }) .style('stroke-width', String(1)+'px') .attr('r', String(7)+'px') - .on("mouseover", function(d) { + .on('mouseover', function(d) { d3.select(this).style('stroke-width', String(3)+'px'); d3.select(this.parentNode.parentNode) .selectAll('.connect-line') .attr('visibility', 'visible'); }) - .on("mouseout", function(d) { + .on('mouseout', function(d) { d3.select(this).style('stroke-width', String(1)+'px'); d3.select(this.parentNode.parentNode) .selectAll('.connect-line') @@ -401,7 +401,7 @@ define(["utils", "data_styles"], function(utils, data_styles) { update_selection .attr('visibility', 'visible') .attr('transform', function(d) { - if (d.x==null || d.y==null) return ""; + if (d.x==null || d.y==null) return ''; return 'translate('+d.x+','+d.y+')'; }); @@ -438,7 +438,7 @@ define(["utils", "data_styles"], function(utils, data_styles) { update_selection .attr('d', function(d) { if (d.x==null || d.y==null || d.source_x==null || d.source_y==null) - return ""; + return ''; return 'M0, 0 '+(d.source_x-d.x)+','+(d.source_y-d.y); }); } @@ -508,7 +508,7 @@ define(["utils", "data_styles"], function(utils, data_styles) { }) .call(turn_off_drag) .call(drag_behavior) - .on("click", click_fn) + .on('click', click_fn) .on('mouseover', mouseover_fn) .on('mouseout', mouseout_fn); @@ -517,8 +517,8 @@ define(["utils", "data_styles"], function(utils, data_styles) { .attr('transform', function(d) { return 'translate('+d.label_x+','+d.label_y+')'; }) - .style("font-size", function(d) { - return String(20)+"px"; + .style('font-size', function(d) { + return String(20)+'px'; }) .text(function(d) { var t = d.bigg_id; @@ -543,7 +543,7 @@ define(["utils", "data_styles"], function(utils, data_styles) { utils.check_undefined(arguments, ['update_selection', 'label_click', 'label_drag_behavior']); update_selection - .attr("transform", function(d) { return "translate("+d.x+","+d.y+")";}) + .attr('transform', function(d) { return 'translate('+d.x+','+d.y+')';}) .on('click', label_click) .call(turn_off_drag) .call(label_drag_behavior); diff --git a/escher/lib/escher.1.0.0b2.js b/escher/lib/escher.1.0.0b2.js index 7df4d049..5a06d4e9 100644 --- a/escher/lib/escher.1.0.0b2.js +++ b/escher/lib/escher.1.0.0b2.js @@ -1810,7 +1810,7 @@ define('data_styles',["utils"], function(utils) { -define('draw',["utils", "data_styles"], function(utils, data_styles) { +define('draw',['utils', 'data_styles'], function(utils, data_styles) { return { create_reaction: create_reaction, update_reaction: update_reaction, create_node: create_node, @@ -1836,10 +1836,10 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { function update_membrane(update_selection) { utils.check_undefined(arguments, ['enter_selection']); update_selection - .attr("width", function(d){ return d.width; }) - .attr("height", function(d){ return d.height; }) - .attr("transform", function(d){return "translate("+d.x+","+d.y+")";}) - .style("stroke-width", function(d) { return 10; }) + .attr('width', function(d){ return d.width; }) + .attr('height', function(d){ return d.height; }) + .attr('transform', function(d){return 'translate('+d.x+','+d.y+')';}) + .style('stroke-width', function(d) { return 10; }) .attr('rx', function(d){ return 20; }) .attr('ry', function(d){ return 20; }); } @@ -1926,7 +1926,7 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { // update_selection // .attr('d', function(d) { // if (d.x==null || d.y==null || d.source_x==null || d.source_y==null) - // return ""; + // return ''; // return 'M0, 0 '+(d.source_x-d.x)+','+(d.source_y-d.y); // }); // } @@ -1942,13 +1942,13 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { sel.append('text') .attr('class', 'reaction-label label') .style('cursor', 'default'); - // .on("mouseover", function(d) { + // .on('mouseover', function(d) { // d3.select(this).style('stroke-width', String(3)+'px'); // d3.select(this.parentNode) // .selectAll('.connect-line') // .attr('visibility', 'visible'); // }) - // .on("mouseout", function(d) { + // .on('mouseout', function(d) { // d3.select(this).style('stroke-width', String(1)+'px'); // d3.select(this.parentNode) // .selectAll('.connect-line') @@ -1972,8 +1972,8 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { return t; }).attr('transform', function(d) { return 'translate('+d.label_x+','+d.label_y+')'; - }).style("font-size", function(d) { - return String(30)+"px"; + }).style('font-size', function(d) { + return String(30)+'px'; }) .call(turn_off_drag) .call(label_drag_behavior); @@ -2105,7 +2105,7 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { arrowheads.enter().append('path') .classed('arrowhead', true); // update arrowheads - arrowheads.attr("d", function(d) { + arrowheads.attr('d', function(d) { var markerWidth = 20, markerHeight = 13; if (has_reaction_data && reaction_data_styles.indexOf('size')!==-1) { var f = d.data; @@ -2181,13 +2181,13 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { .attr('class', function(d) { return 'bezier bezier'+d.bezier; }) .style('stroke-width', String(1)+'px') .attr('r', String(7)+'px') - .on("mouseover", function(d) { + .on('mouseover', function(d) { d3.select(this).style('stroke-width', String(3)+'px'); d3.select(this.parentNode.parentNode) .selectAll('.connect-line') .attr('visibility', 'visible'); }) - .on("mouseout", function(d) { + .on('mouseout', function(d) { d3.select(this).style('stroke-width', String(1)+'px'); d3.select(this.parentNode.parentNode) .selectAll('.connect-line') @@ -2211,7 +2211,7 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { update_selection .attr('visibility', 'visible') .attr('transform', function(d) { - if (d.x==null || d.y==null) return ""; + if (d.x==null || d.y==null) return ''; return 'translate('+d.x+','+d.y+')'; }); @@ -2248,7 +2248,7 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { update_selection .attr('d', function(d) { if (d.x==null || d.y==null || d.source_x==null || d.source_y==null) - return ""; + return ''; return 'M0, 0 '+(d.source_x-d.x)+','+(d.source_y-d.y); }); } @@ -2318,7 +2318,7 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { }) .call(turn_off_drag) .call(drag_behavior) - .on("click", click_fn) + .on('click', click_fn) .on('mouseover', mouseover_fn) .on('mouseout', mouseout_fn); @@ -2327,8 +2327,8 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { .attr('transform', function(d) { return 'translate('+d.label_x+','+d.label_y+')'; }) - .style("font-size", function(d) { - return String(20)+"px"; + .style('font-size', function(d) { + return String(20)+'px'; }) .text(function(d) { var t = d.bigg_id; @@ -2353,7 +2353,7 @@ define('draw',["utils", "data_styles"], function(utils, data_styles) { utils.check_undefined(arguments, ['update_selection', 'label_click', 'label_drag_behavior']); update_selection - .attr("transform", function(d) { return "translate("+d.x+","+d.y+")";}) + .attr('transform', function(d) { return 'translate('+d.x+','+d.y+')';}) .on('click', label_click) .call(turn_off_drag) .call(label_drag_behavior); @@ -2809,10 +2809,22 @@ define('Behavior',["utils", "build"], function(utils, build) { Has the following attributes: - Behavior.node_click - Behavior.node_drag - Behavior.bezier_drag - Behavior.label_drag + Behavior.rotation_drag: + + Behavior.selectable_click: + + Behavior.node_mouseover: + + Behavior.node_mouseout: + + Behavior.selectable_drag: + + Behavior.bezier_drag: + + Behavior.reaction_label_drag: + + Behavior.node_label_drag: + */ var Behavior = utils.make_class(); @@ -2820,16 +2832,15 @@ define('Behavior',["utils", "build"], function(utils, build) { toggle_rotation_mode: toggle_rotation_mode, turn_everything_on: turn_everything_on, turn_everything_off: turn_everything_off, - toggle_node_click: toggle_node_click, - toggle_node_drag: toggle_node_drag, - toggle_text_label_click: toggle_text_label_click, + toggle_selectable_click: toggle_selectable_click, + toggle_selectable_drag: toggle_selectable_drag, toggle_label_drag: toggle_label_drag, - get_node_drag: get_node_drag, + get_selectable_drag: get_selectable_drag, get_bezier_drag: get_bezier_drag, get_reaction_label_drag: get_reaction_label_drag, get_node_label_drag: get_node_label_drag, - get_text_label_drag: get_text_label_drag, - get_generic_drag: get_generic_drag }; + get_generic_drag: get_generic_drag, + get_generic_angular_drag: get_generic_angular_drag }; return Behavior; @@ -2846,33 +2857,29 @@ define('Behavior',["utils", "build"], function(utils, build) { this.rotation_drag = d3.behavior.drag(); // init empty - this.node_click = null; + this.selectable_click = null; this.node_mouseover = null; this.node_mouseout = null; - this.node_drag = this.empty_behavior; + this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; - this.text_label_click = null; - this.text_label_drag = this.empty_behavior; this.turn_everything_on(); } function turn_everything_on() { /** Toggle everything except rotation mode. */ - this.toggle_node_click(true); - this.toggle_node_drag(true); - this.toggle_text_label_click(true); + this.toggle_selectable_click(true); + this.toggle_selectable_drag(true); this.toggle_label_drag(true); } function turn_everything_off() { /** Toggle everything except rotation mode. */ - this.toggle_node_click(false); - this.toggle_node_drag(false); - this.toggle_text_label_click(false); + this.toggle_selectable_click(false); + this.toggle_selectable_drag(false); this.toggle_label_drag(false); } @@ -2912,43 +2919,41 @@ define('Behavior',["utils", "build"], function(utils, build) { // silence other listeners d3.event.sourceEvent.stopPropagation(); }, - drag_fn = function(d, displacement, total_displacement, location) { - var angle = utils.angle_for_event(displacement, - location, - this.center); + drag_fn = function(d, angle, total_angle, center) { var updated = build.rotate_nodes(selected_nodes, reactions, - angle, this.center); + angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); - }.bind(this), + }, end_fn = function(d) {}, - undo_fn = function(d, displacement, location) { + undo_fn = function(d, total_angle, center) { // undo - var total_angle = utils.angle_for_event(displacement, - location, - this.center); - var these_nodes = {}; - selected_node_ids.forEach(function(id) { these_nodes[id] = nodes[id]; }); + selected_node_ids.forEach(function(id) { + these_nodes[id] = nodes[id]; + }); var updated = build.rotate_nodes(these_nodes, reactions, - -total_angle, utils.clone(this.center)); + -total_angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); - }.bind(this), - redo_fn = function(d, displacement, location) { + }, + redo_fn = function(d, total_angle, center) { // redo - var total_angle = utils.angle_for_event(displacement, - location, - this.center), - these_nodes = {}; - selected_node_ids.forEach(function(id) { these_nodes[id] = nodes[id]; }); + var these_nodes = {}; + selected_node_ids.forEach(function(id) { + these_nodes[id] = nodes[id]; + }); var updated = build.rotate_nodes(these_nodes, reactions, - total_angle, utils.clone(this.center)); + total_angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); + }, + center_fn = function() { + return this.center; }.bind(this); - this.rotation_drag = this.get_generic_drag(start_fn, drag_fn, end_fn, - undo_fn, redo_fn, this.map.sel); + this.rotation_drag = this.get_generic_angular_drag(start_fn, drag_fn, end_fn, + undo_fn, redo_fn, center_fn, + this.map.sel); selection_background.call(this.rotation_drag); @@ -3011,17 +3016,18 @@ define('Behavior',["utils", "build"], function(utils, build) { } } - function toggle_node_click(on_off) { + function toggle_selectable_click(on_off) { /** With no argument, toggle the node click on or off. Pass in a boolean argument to set the on/off state. */ - if (on_off===undefined) on_off = this.node_click==null; + if (on_off===undefined) on_off = this.selectable_click==null; if (on_off) { var map = this.map; - this.node_click = function(d) { - map.select_metabolite(this, d); + this.selectable_click = function(d) { + if (d3.event.defaultPrevented) return; // click suppressed + map.select_selectable(this, d); d3.event.stopPropagation(); }; this.node_mouseover = function(d) { @@ -3033,42 +3039,26 @@ define('Behavior',["utils", "build"], function(utils, build) { d3.select(this).style('stroke-width', null); }; } else { - this.node_click = null; + this.selectable_click = null; this.node_mouseover = null; this.node_mouseout = null; this.map.sel.select('#nodes') .selectAll('.node-circle').style('stroke-width', null); } } - function toggle_text_label_click(on_off) { - /** With no argument, toggle the node click on or off. - Pass in a boolean argument to set the on/off state. - - */ - if (on_off===undefined) on_off = this.text_label_click==null; - if (on_off) { - var map = this.map; - this.text_label_click = function(d) { - map.select_text_label(this, d); - d3.event.stopPropagation(); - }; - } else { - this.text_label_click = null; - } - } - function toggle_node_drag(on_off) { + function toggle_selectable_drag(on_off) { /** With no argument, toggle the node drag & bezier drag on or off. Pass in a boolean argument to set the on/off state. */ - if (on_off===undefined) on_off = this.node_drag===this.empty_behavior; + if (on_off===undefined) on_off = this.selectable_drag===this.empty_behavior; if (on_off) { - this.node_drag = this.get_node_drag(this.map, this.undo_stack); + this.selectable_drag = this.get_selectable_drag(this.map, this.undo_stack); this.bezier_drag = this.get_bezier_drag(this.map, this.undo_stack); } else { - this.node_drag = this.empty_behavior; + this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; } } @@ -3082,84 +3072,125 @@ define('Behavior',["utils", "build"], function(utils, build) { if (on_off) { this.reaction_label_drag = this.get_reaction_label_drag(this.map); this.node_label_drag = this.get_node_label_drag(this.map); - this.text_label_drag = this.get_text_label_drag(this.map); } else { this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; - this.text_label_drag = this.empty_behavior; } } - function get_node_drag(map, undo_stack) { + function get_selectable_drag(map, undo_stack) { + /** Drag the selected nodes and text labels. + + */ + // define some variables var behavior = d3.behavior.drag(), + the_timeout = null, total_displacement = null, - nodes_to_drag = null, + // for nodes + node_ids_to_drag = null, reaction_ids = null, - the_timeout = null; + // for text labels + text_label_ids_to_drag = null, + move_label = function(text_label_id, displacement) { + var text_label = map.text_labels[text_label_id]; + text_label.x = text_label.x + displacement.x; + text_label.y = text_label.y + displacement.y; + }; behavior.on("dragstart", function () { - // Note that dragstart is called even for a click event - var data = this.parentNode.__data__, - bigg_id = data.bigg_id, - node_group = this.parentNode; // silence other listeners - d3.event.sourceEvent.stopPropagation(); + d3.event.sourceEvent.stopPropagation(); console.log('dragstart'); // remember the total displacement for later - total_displacement = {}; - // Move element to back (for the next step to work). Wait 200ms - // before making the move, becuase otherwise the element will be - // deleted before the click event gets called, and selection - // will stop working. - the_timeout = window.setTimeout(function() { - node_group.parentNode.insertBefore(node_group,node_group.parentNode.firstChild); - }, 200); - // prepare to combine metabolites - map.sel.selectAll('.metabolite-circle') - .on('mouseover.combine', function(d) { - if (d.bigg_id==bigg_id && d.node_id!=data.node_id) { - d3.select(this).style('stroke-width', String(12)+'px') - .classed('node-to-combine', true); - } - }).on('mouseout.combine', function(d) { - if (d.bigg_id==bigg_id) { - map.sel.selectAll('.node-to-combine').style('stroke-width', String(2)+'px') - .classed('node-to-combine', false); - } - }); + // total_displacement = {}; + total_displacement = {x: 0, y: 0}; + + // If a text label is selected, the rest is not necessary + if (d3.select(this).attr('class').indexOf('text-label')==-1) { + // Note that dragstart is called even for a click event + var data = this.parentNode.__data__, + bigg_id = data.bigg_id, + node_group = this.parentNode; + // Move element to back (for the next step to work). Wait 200ms + // before making the move, becuase otherwise the element will be + // deleted before the click event gets called, and selection + // will stop working. + the_timeout = window.setTimeout(function() { + node_group.parentNode.insertBefore(node_group,node_group.parentNode.firstChild); + }, 200); + // prepare to combine metabolites + map.sel.selectAll('.metabolite-circle') + .on('mouseover.combine', function(d) { + if (d.bigg_id==bigg_id && d.node_id!=data.node_id) { + d3.select(this).style('stroke-width', String(12)+'px') + .classed('node-to-combine', true); + } + }).on('mouseout.combine', function(d) { + if (d.bigg_id==bigg_id) { + map.sel.selectAll('.node-to-combine').style('stroke-width', String(2)+'px') + .classed('node-to-combine', false); + } + }); + } }); behavior.on("drag", function() { - var grabbed_id = this.parentNode.__data__.node_id, - selected_ids = map.get_selected_node_ids(); - nodes_to_drag = []; - // choose the nodes to drag - if (selected_ids.indexOf(grabbed_id)==-1) { - nodes_to_drag.push(grabbed_id); + // get the grabbed id + var grabbed = {}; + if (d3.select(this).attr('class').indexOf('text-label')==-1) { + // if it is a node + grabbed['type'] = 'node'; + grabbed['id'] = this.parentNode.__data__.node_id; + } else { + // if it is a text label + grabbed['type'] = 'text-label'; + grabbed['id'] = this.__data__.text_label_id; + } + + var selected_node_ids = map.get_selected_node_ids(), + selected_text_label_ids = map.get_selected_text_label_ids(); + node_ids_to_drag = []; text_label_ids_to_drag = []; + // choose the nodes and text labels to drag + if (grabbed['type']=='node' && + selected_node_ids.indexOf(grabbed['id'])==-1) { + node_ids_to_drag.push(grabbed['id']); + } else if (grabbed['type']=='text-label' && + selected_text_label_ids.indexOf(grabbed['id'])==-1) { + text_label_ids_to_drag.push(grabbed['id']); } else { - nodes_to_drag = selected_ids; + node_ids_to_drag = selected_node_ids; + text_label_ids_to_drag = selected_text_label_ids; } reaction_ids = []; - nodes_to_drag.forEach(function(node_id) { + var displacement = { x: d3.event.dx, + y: d3.event.dy }; + total_displacement = utils.c_plus_c(total_displacement, displacement); + node_ids_to_drag.forEach(function(node_id) { // update data var node = map.nodes[node_id], - displacement = { x: d3.event.dx, - y: d3.event.dy }, updated = build.move_node_and_dependents(node, node_id, map.reactions, displacement); reaction_ids = utils.unique_concat([reaction_ids, updated.reaction_ids]); // remember the displacements - if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; - total_displacement[node_id] = utils.c_plus_c(total_displacement[node_id], displacement); + // if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; + // total_displacement[node_id] = utils.c_plus_c(total_displacement[node_id], displacement); + }); + text_label_ids_to_drag.forEach(function(text_label_id) { + move_label(text_label_id, displacement); + // remember the displacements + // if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; + // total_displacement[node_id] = utils.c_plus_c(total_displacement[node_id], displacement); }); // draw - map.draw_these_nodes(nodes_to_drag); + map.draw_these_nodes(node_ids_to_drag); map.draw_these_reactions(reaction_ids); + map.draw_these_text_labels(text_label_ids_to_drag); }); behavior.on("dragend", function() { - if (nodes_to_drag===null) { + if (node_ids_to_drag===null) { // Dragend can be called when drag has not been called. In this, // case, do nothing. total_displacement = null; - nodes_to_drag = null; + node_ids_to_drag = null; + text_label_ids_to_drag = null; reaction_ids = null; the_timeout = null; return; @@ -3213,26 +3244,36 @@ define('Behavior',["utils", "build"], function(utils, build) { var saved_displacement = utils.clone(total_displacement), // BUG TODO this variable disappears! // Happens sometimes when you drag a node, then delete it, then undo twice - saved_node_ids = utils.clone(nodes_to_drag), + saved_node_ids = utils.clone(node_ids_to_drag), + saved_text_label_ids = utils.clone(text_label_ids_to_drag), saved_reaction_ids = utils.clone(reaction_ids); undo_stack.push(function() { // undo saved_node_ids.forEach(function(node_id) { var node = map.nodes[node_id]; build.move_node_and_dependents(node, node_id, map.reactions, - utils.c_times_scalar(saved_displacement[node_id], -1)); + utils.c_times_scalar(saved_displacement, -1)); + }); + saved_text_label_ids.forEach(function(text_label_id) { + move_label(text_label_id, + utils.c_times_scalar(saved_displacement, -1)); }); map.draw_these_nodes(saved_node_ids); map.draw_these_reactions(saved_reaction_ids); + map.draw_these_text_labels(saved_text_label_ids); }, function () { // redo saved_node_ids.forEach(function(node_id) { var node = map.nodes[node_id]; build.move_node_and_dependents(node, node_id, map.reactions, - saved_displacement[node_id]); + saved_displacement); + }); + saved_text_label_ids.forEach(function(text_label_id) { + move_label(text_label_id, saved_displacement); }); map.draw_these_nodes(saved_node_ids); map.draw_these_reactions(saved_reaction_ids); + map.draw_these_text_labels(saved_text_label_ids); }); } @@ -3246,7 +3287,8 @@ define('Behavior',["utils", "build"], function(utils, build) { // clear the shared variables total_displacement = null; - nodes_to_drag = null; + node_ids_to_drag = null; + text_label_ids_to_drag = null; reaction_ids = null; the_timeout = null; }); @@ -3356,32 +3398,7 @@ define('Behavior',["utils", "build"], function(utils, build) { return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, this.map.sel); } - function get_text_label_drag(map) { - var move_label = function(text_label_id, displacement) { - var text_label = map.text_labels[text_label_id]; - text_label.x = text_label.x + displacement.x; - text_label.y = text_label.y + displacement.y; - }, - start_fn = function(d) { - }, - drag_fn = function(d, displacement, total_displacement) { - // draw - move_label(d.text_label_id, displacement); - map.draw_these_text_labels([d.text_label_id]); - }, - end_fn = function(d) { - }, - undo_fn = function(d, displacement) { - move_label(d.text_label_id, utils.c_times_scalar(displacement, -1)); - map.draw_these_text_labels([d.text_label_id]); - }, - redo_fn = function(d, displacement) { - move_label(d.text_label_id, displacement); - map.draw_these_text_labels([d.text_label_id]); - }; - return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, - redo_fn, this.map.sel); - } + function get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, relative_to_selection) { /** Make a generic drag behavior, with undo/redo. @@ -3442,6 +3459,73 @@ define('Behavior',["utils", "build"], function(utils, build) { }); return behavior; } + + function get_generic_angular_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, + get_center, relative_to_selection) { + /** Make a generic drag behavior, with undo/redo. Supplies angles in + place of displacements. + + start_fn: function(d) Called at dragstart. + + drag_fn: function(d, displacement, total_displacement) Called during + drag. + + end_fn: + + undo_fn: + + redo_fn: + + get_center: + + relative_to_selection: a d3 selection that the locations are calculated against. + + */ + + // define some variables + var behavior = d3.behavior.drag(), + total_angle, + undo_stack = this.undo_stack, + rel = relative_to_selection.node(); + + behavior.on("dragstart", function (d) { + // silence other listeners + d3.event.sourceEvent.stopPropagation(); + total_angle = 0; + start_fn(d); + }); + behavior.on("drag", function(d) { + // update data + var displacement = { x: d3.event.dx, + y: d3.event.dy }, + location = { x: d3.mouse(rel)[0], + y: d3.mouse(rel)[1] }, + center = get_center(), + angle = utils.angle_for_event(displacement, + location, + center); + // remember the displacement + total_angle = total_angle + angle; + drag_fn(d, angle, total_angle, center); + }); + behavior.on("dragend", function(d) { + // add to undo/redo stack + // remember the displacement, dragged nodes, and reactions + var saved_d = utils.clone(d), + saved_angle = total_angle, + saved_center = utils.clone(get_center()); + + undo_stack.push(function() { + // undo + undo_fn(saved_d, saved_angle, saved_center); + }, function () { + // redo + redo_fn(saved_d, saved_angle, saved_center); + }); + end_fn(d); + }); + return behavior; + } }); define('Scale',["utils"], function(utils) { @@ -7128,8 +7212,28 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb Arguments --------- - selection: A d3 selection for a node to place the map inside. Should be an SVG element. - behavior: A Behavior object which defines the interactivity of the map. + + svg: + + css: + + selection: A d3 selection for a node to place the map inside. + + selection: + + zoom_container: + + settings: + + reaction_data: + + metabolite_data: + + cobra_model: + + canvas_size_and_loc: + + enable_search: */ @@ -7154,7 +7258,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb clear_map: clear_map, // selection select_none: select_none, - select_metabolite: select_metabolite, + select_selectable: select_selectable, select_metabolite_with_id: select_metabolite_with_id, select_single_node: select_single_node, deselect_nodes: deselect_nodes, @@ -7591,14 +7695,14 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb defs = this.defs, default_reaction_color = this.default_reaction_color, bezier_drag_behavior = this.behavior.bezier_drag, - node_click_fn = this.behavior.node_click, + node_click_fn = this.behavior.selectable_click, node_mouseover_fn = this.behavior.node_mouseover, node_mouseout_fn = this.behavior.node_mouseout, - node_drag_behavior = this.behavior.node_drag, + node_drag_behavior = this.behavior.selectable_drag, reaction_label_drag = this.behavior.reaction_label_drag, node_label_drag = this.behavior.node_label_drag, - text_label_click = this.behavior.text_label_click, - text_label_drag = this.behavior.text_label_drag, + text_label_click = this.behavior.selectable_click, + text_label_drag = this.behavior.selectable_drag, has_reaction_data = this.has_reaction_data(), reaction_data_styles = this.settings.data_styles['reaction'], has_metabolite_data = this.has_metabolite_data(), @@ -7707,10 +7811,10 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb var scale = this.scale, reactions = this.reactions, nodes = this.nodes, - node_click_fn = this.behavior.node_click, + node_click_fn = this.behavior.selectable_click, node_mouseover_fn = this.behavior.node_mouseover, node_mouseout_fn = this.behavior.node_mouseout, - node_drag_behavior = this.behavior.node_drag, + node_drag_behavior = this.behavior.selectable_drag, node_label_drag = this.behavior.node_label_drag, metabolite_data_styles = this.settings.data_styles['metabolite'], has_metabolite_data = this.has_metabolite_data(); @@ -7748,8 +7852,8 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb } function draw_these_text_labels(text_label_ids) { var text_labels = this.text_labels, - text_label_click = this.behavior.text_label_click, - text_label_drag = this.behavior.text_label_drag; + text_label_click = this.behavior.selectable_click, + text_label_drag = this.behavior.selectable_drag; // find text labels for text_label_ids var text_label_subset = {}, @@ -7966,9 +8070,10 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb } function select_metabolite_with_id(node_id) { - // deselect all text labels - this.deselect_text_labels(); + /** Select a metabolite with the given id, and turn off the reaction + target. + */ var node_selection = this.sel.select('#nodes').selectAll('.node'), coords, selected_node; @@ -7983,27 +8088,39 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb this.sel.selectAll('.start-reaction-target').style('visibility', 'hidden'); this.callback_manager.run('select_metabolite_with_id', selected_node, coords); } - function select_metabolite(sel, d) { - // deselect all text labels - this.deselect_text_labels(); - - var node_selection = this.sel.select('#nodes').selectAll('.node'), - shift_key_on = this.key_manager.held_keys.shift; + function select_selectable(node, d) { + /** Select a metabolite or text label, and manage the shift key. + + */ + var classable_selection = this.sel.selectAll('#nodes,#text-labels') + .selectAll('.node,.text-label'), + shift_key_on = this.key_manager.held_keys.shift, + classable_node; + if (d3.select(node).attr('class').indexOf('text-label') == -1) { + // node + classable_node = node.parentNode; + } else { + // text-label + classable_node = node; + } + // toggle selection if (shift_key_on) { - d3.select(sel.parentNode) - .classed("selected", !d3.select(sel.parentNode).classed("selected")); + d3.select(classable_node) + .classed("selected", !d3.select(classable_node).classed("selected")); + } else { + classable_selection.classed("selected", function(p) { return d === p; }); } - else node_selection.classed("selected", function(p) { return d === p; }); + // run the select_metabolite callback var selected_nodes = this.sel.select('#nodes').selectAll('.selected'), - count = 0, + node_count = 0, coords, selected_node; selected_nodes.each(function(d) { selected_node = d; coords = { x: d.x, y: d.y }; - count++; + node_count++; }); - this.callback_manager.run('select_metabolite', count, selected_node, coords); + this.callback_manager.run('select_selectable', node_count, selected_node, coords); } function select_single_node() { /** Unselect all but one selected node, and return the node. @@ -8105,7 +8222,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb this.extend_nodes(saved_nodes); this.extend_reactions(saved_reactions); - var reactions_to_draw = Object.keys(saved_reactions); + var reaction_ids_to_draw = Object.keys(saved_reactions); saved_segment_objs_w_segments.forEach(function(segment_obj) { var segment = segment_obj.segment; this.reactions[segment_obj.reaction_id] @@ -8120,8 +8237,8 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb segment_id: segment_obj.segment_id }); }.bind(this)); - if (reactions_to_draw.indexOf(segment_obj.reaction_id)==-1) - reactions_to_draw.push(segment_obj.reaction_id); + if (reaction_ids_to_draw.indexOf(segment_obj.reaction_id)==-1) + reaction_ids_to_draw.push(segment_obj.reaction_id); }.bind(this)); // apply the reaction and node data @@ -8129,9 +8246,9 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb if (this.has_reaction_data()) { var scale_changed = this.update_reaction_data_domain(); if (scale_changed) this.draw_all_reactions(); - else this.draw_these_reactions(Object.keys(reactions_to_draw)); + else this.draw_these_reactions(reaction_ids_to_draw); } else { - this.draw_these_reactions(Object.keys(reactions_to_draw)); + this.draw_these_reactions(reaction_ids_to_draw); } if (this.has_metabolite_data()) { var scale_changed = this.update_metabolite_data_domain(); @@ -9248,7 +9365,7 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa if (this.is_active) this.reload(selected_node, coords, false); this.hide_target(); }.bind(this)); - map.callback_manager.set('select_metabolite.input', function(count, selected_node, coords) { + map.callback_manager.set('select_selectable.input', function(count, selected_node, coords) { this.hide_target(); if (count == 1 && this.is_active && coords) { this.reload(selected_node, coords, false); @@ -9609,7 +9726,14 @@ define('CobraModel',["utils", "data_styles"], function(utils, data_styles) { define('Brush',["utils"], function(utils) { /** Define a brush to select elements in a map. - Brush(selection, is_enabled, map, insert_after) + Arguments + --------- + + selection: A d3 selection to place the brush in. + + is_enabled: Whether to turn the brush on. + + map: An instance of escher.Map. insert_after: A d3 selector string to choose the svg element that the brush will be inserted after. Often a canvas element (e.g. '.canvas-group'). @@ -9655,7 +9779,7 @@ define('Brush',["utils"], function(utils) { } function setup_selection_brush() { var selection = this.brush_sel, - nodes_selection = this.map.sel.select('#nodes'), + selectable_selection = this.map.sel.selectAll('#nodes,#text-labels'), size_and_location = this.map.canvas.size_and_location(), width = size_and_location.width, height = size_and_location.height, @@ -9670,10 +9794,12 @@ define('Brush',["utils"], function(utils) { selection; if (shift_key_on) { // when shift is pressed, ignore the currently selected nodes - selection = nodes_selection.selectAll('.node:not(.selected)'); + selection = selectable_selection + .selectAll('.node,.text-label:not(.selected)'); } else { // otherwise, brush all nodes - selection = nodes_selection.selectAll('.node'); + selection = selectable_selection + .selectAll('.node,.text-label'); } selection.classed("selected", function(d) { var sx = d.x, sy = d.y; @@ -10639,7 +10765,7 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush */ // Begin with some definitions - var node_click_enabled = true, + var selectable_click_enabled = true, shift_key_on = false; // set up this callback manager @@ -10784,12 +10910,13 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush this.map.canvas.toggle_resize(mode=='zoom' || mode=='brush'); // behavior this.map.behavior.toggle_rotation_mode(mode=='rotate'); - this.map.behavior.toggle_node_click(mode=='build' || mode=='brush'); - this.map.behavior.toggle_node_drag(mode=='brush'); - this.map.behavior.toggle_text_label_click(mode=='brush'); + this.map.behavior.toggle_selectable_click(mode=='build' || mode=='brush' || mode=='rotate'); + this.map.behavior.toggle_selectable_drag(mode=='brush' || mode=='rotate'); this.map.behavior.toggle_label_drag(mode=='brush'); if (mode=='view') this.map.select_none(); + if (mode=='rotate') + this.map.deselect_text_labels(); this.map.draw_everything(); } function view_mode() { @@ -11073,13 +11200,13 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush brush.toggle(false); was_enabled.zoom = zoom_container.zoom_on; zoom_container.toggle_zoom(false); - was_enabled.node_click = map.behavior.node_click!=null; - map.behavior.toggle_node_click(false); + was_enabled.selectable_click = map.behavior.selectable_click!=null; + map.behavior.toggle_selectable_click(false); }); map.callback_manager.set('end_rotation', function() { brush.toggle(was_enabled.brush); zoom_container.toggle_zoom(was_enabled.zoom); - map.behavior.toggle_node_click(was_enabled.node_click); + map.behavior.toggle_selectable_click(was_enabled.selectable_click); was_enabled = {}; }); } diff --git a/escher/lib/escher.1.0.0b2.min.js b/escher/lib/escher.1.0.0b2.min.js index 089478d7..60bc4bbc 100644 --- a/escher/lib/escher.1.0.0b2.min.js +++ b/escher/lib/escher.1.0.0b2.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label").style("cursor","default")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label").style("cursor","default")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("text").attr("class","text-label label").style("cursor","default").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.node_click=null,this.node_mouseover=null,this.node_mouseout=null,this.node_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.text_label_click=null,this.text_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_node_click(!0),this.toggle_node_drag(!0),this.toggle_text_label_click(!0),this.toggle_label_drag(!0)}function s(){this.toggle_node_click(!1),this.toggle_node_drag(!1),this.toggle_text_label_click(!1),this.toggle_label_drag(!1)}function o(n){function v(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function m(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function g(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=g(s),v.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(n,r,i,u){var f=e.angle_for_event(r,u,this.center),l=t.rotate_nodes(s,a,f,this.center);o.draw_these_nodes(l.node_ids),o.draw_these_reactions(l.reaction_ids)}.bind(this),h=function(e){},p=function(n,r,i){var s=e.angle_for_event(r,i,this.center),l={};u.forEach(function(e){l[e]=f[e]});var c=t.rotate_nodes(l,a,-s,e.clone(this.center));o.draw_these_nodes(c.node_ids),o.draw_these_reactions(c.reaction_ids)}.bind(this),d=function(n,r,i){var s=e.angle_for_event(r,i,this.center),l={};u.forEach(function(e){l[e]=f[e]});var c=t.rotate_nodes(l,a,s,e.clone(this.center));o.draw_these_nodes(c.node_ids),o.draw_these_reactions(c.reaction_ids)}.bind(this);this.rotation_drag=this.get_generic_drag(l,c,h,p,d,this.map.sel),i.call(this.rotation_drag)}else m.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.node_click==null);if(e){var t=this.map;this.node_click=function(e){t.select_metabolite(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.node_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_label_click==null);if(e){var t=this.map;this.text_label_click=function(e){t.select_text_label(this,e),d3.event.stopPropagation()}}else this.text_label_click=null}function f(e){e===undefined&&(e=this.node_drag===this.empty_behavior),e?(this.node_drag=this.get_node_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.node_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map),this.text_label_drag=this.get_text_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.text_label_drag=this.empty_behavior)}function c(n,r){function f(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null;return i.on("dragstart",function(){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;d3.event.sourceEvent.stopPropagation(),s={},a=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}),i.on("drag",function(){var r=this.parentNode.__data__.node_id,i=n.get_selected_node_ids();o=[],i.indexOf(r)==-1?o.push(r):o=i,u=[],o.forEach(function(r){var i=n.nodes[r],o={x:d3.event.dx,y:d3.event.dy},a=t.move_node_and_dependents(i,r,n.reactions,o);u=e.unique_concat([u,a.reaction_ids]),r in s||(s[r]={x:0,y:0}),s[r]=e.c_plus_c(s[r],o)}),n.draw_these_nodes(o),n.draw_these_reactions(u)}),i.on("dragend",function(){if(o===null){s=null,o=null,u=null,a=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var l=i[0],c=this.parentNode.__data__.node_id,h=e.clone(n.nodes[c]),p=f(l,c);r.push(function(){n.nodes[c]=h;var e=n.nodes[l],t=[];p.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==l?i.from_node_id=c:i.to_node_id==l?i.to_node_id=c:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([c]),n.draw_these_reactions(t)},function(){f(l,c)})}else{var d=e.clone(s),v=e.clone(o),m=e.clone(u);r.push(function(){v.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(d[r],-1))}),n.draw_these_nodes(v),n.draw_these_reactions(m)},function(){v.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,d[e])}),n.draw_these_nodes(v),n.draw_these_reactions(m)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(a),s=null,o=null,u=null,a=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.text_labels[e];r.x=r.x+n.x,r.y=r.y+n.y},r=function(e){},i=function(e,r,i){n(e.text_label_id,r),t.draw_these_text_labels([e.text_label_id])},s=function(e){},o=function(r,i){n(r.text_label_id,e.c_times_scalar(i,-1)),t.draw_these_text_labels([r.text_label_id])},u=function(e,r){n(e.text_label_id,r),t.draw_these_text_labels([e.text_label_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_node_click:u,toggle_node_drag:f,toggle_text_label_click:a,toggle_label_drag:l,get_node_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_text_label_drag:v,get_generic_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.node_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.node_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.text_label_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(n){e[n.node_id]=t.nodes[n.node_id]}),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(n){e[n.text_label_id]=t.text_labels[n.text_label_id]}),e}function z(){this.sel.selectAll(".selected").classed("selected",!1)}function W(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function X(e,t){this.deselect_text_labels();var n=this.sel.select("#nodes").selectAll(".node"),r=this.key_manager.held_keys.shift;r?d3.select(e.parentNode).classed("selected",!d3.select(e.parentNode).classed("selected")):n.classed("selected",function(e){return t===e});var i=this.sel.select("#nodes").selectAll(".selected"),s=0,o,u;i.each(function(e){u=e,o={x:e.x,y:e.y},s++}),this.callback_manager.run("select_metabolite",s,u,o)}function V(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function $(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function J(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function K(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Q(){var e=this.get_selected_nodes();Object.keys(e).length>=1&&this.delete_nodes(e);var t=this.get_selected_text_labels();Object.keys(t).length>=1&&this.delete_text_labels(t)}function G(t){var n=this.segments_and_reactions_for_nodes(t),r=n.reactions,i=n.segment_objs_w_segments,s=e.clone(t),o=e.clone(i),u=e.clone(r),a=function(e,n,r){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);a(t,r,i),this.undo_stack.push(function(){this.extend_nodes(s),this.extend_reactions(u);var n=Object.keys(u);o.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in s)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),n.indexOf(e.reaction_id)==-1&&n.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var a=this.update_reaction_data_domain();a?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var a=this.update_metabolite_data_domain();a?this.draw_all_nodes():this.draw_these_nodes(Object.keys(s))}else this.draw_these_nodes(Object.keys(s));t=e.clone(s),i=e.clone(o),r=e.clone(u)}.bind(this),function(){a(t,r,i)}.bind(this))}function Y(t){var n=e.clone(t),r=this,i=function(e){r.delete_text_label_data(Object.keys(t)),r.draw_everything()};i(t),this.undo_stack.push(function(){e.extend(r.text_labels,n),r.draw_these_text_labels(Object.keys(n)),t=e.clone(n)},function(){i(t)})}function Z(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function et(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function tt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function nt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function rt(){this.toggle_beziers(!0)}function it(){this.toggle_beziers(!1)}function st(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ot(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function ut(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function at(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function ft(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),W.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function lt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w)}function ct(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function ht(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function pt(e){this._zoom_extent(e,"nodes")}function dt(e){this._zoom_extent(e,"canvas")}function vt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function mt(){return this.zoom_container.get_size()}function gt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function yt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function wt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Et(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function St(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function xt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Tt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_none:z,select_metabolite:X,select_metabolite_with_id:W,select_single_node:V,deselect_nodes:$,select_text_label:J,deselect_text_labels:K,new_reaction_from_scratch:ot,new_reaction_for_metabolite:ft,cycle_primary_node:lt,make_selected_node_primary:ct,extend_nodes:ut,extend_reactions:at,delete_selected:Q,delete_nodes:G,delete_text_labels:Y,delete_node_data:Z,delete_segment_data:et,delete_reaction_data:tt,delete_text_label_data:nt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:ht,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:st,hide_beziers:it,show_beziers:rt,zoom_extent_nodes:pt,zoom_extent_canvas:dt,_zoom_extent:vt,get_size:mt,zoom_to_reaction:gt,zoom_to_node:yt,highlight_reaction:bt,highlight_node:wt,highlight:Et,save:St,map_for_export:xt,save_svg:Tt},h}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("Input",["utils","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o){function a(e,s,u){var a=e.append("div").attr("id","rxn-input"),f=t(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.selection=a,this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(s instanceof n){this.map=s;var l=90;this.direction_arrow=new o(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s)}else console.error("Cannot set the map. It is not an instance of builder/Map");u instanceof r?(this.zoom_container=u,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new i,this.toggle(!1),this.target_coords=null}function f(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_metabolite.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function l(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function c(){return this.selection.style("display")!="none"}function h(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.selection.style("display","none"),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function p(e){this.selection.style("display","block"),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function d(){this.selection.style("display","none"),this.completely.hideDropDown()}function v(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function m(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.selection.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px"),this.direction_arrow.set_location(e),this.direction_arrow.show()}function g(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function y(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label").style("cursor","default")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label").style("cursor","default")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("text").attr("class","text-label label").style("cursor","default").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function f(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function l(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),console.log("dragstart"),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("text-label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("text-label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="text-label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="text-label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function c(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function h(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function v(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_selectable_drag:a,toggle_label_drag:f,get_selectable_drag:l,get_bezier_drag:c,get_reaction_label_drag:h,get_node_label_drag:p,get_generic_drag:d,get_generic_angular_drag:v},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.selectable_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(n){e[n.node_id]=t.nodes[n.node_id]}),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(n){e[n.text_label_id]=t.text_labels[n.text_label_id]}),e}function z(){this.sel.selectAll(".selected").classed("selected",!1)}function W(e){var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function X(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function V(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function $(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function J(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function K(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Q(){var e=this.get_selected_nodes();Object.keys(e).length>=1&&this.delete_nodes(e);var t=this.get_selected_text_labels();Object.keys(t).length>=1&&this.delete_text_labels(t)}function G(t){var n=this.segments_and_reactions_for_nodes(t),r=n.reactions,i=n.segment_objs_w_segments,s=e.clone(t),o=e.clone(i),u=e.clone(r),a=function(e,n,r){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);a(t,r,i),this.undo_stack.push(function(){this.extend_nodes(s),this.extend_reactions(u);var n=Object.keys(u);o.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in s)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),n.indexOf(e.reaction_id)==-1&&n.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var a=this.update_reaction_data_domain();a?this.draw_all_reactions():this.draw_these_reactions(n)}else this.draw_these_reactions(n);if(this.has_metabolite_data()){var a=this.update_metabolite_data_domain();a?this.draw_all_nodes():this.draw_these_nodes(Object.keys(s))}else this.draw_these_nodes(Object.keys(s));t=e.clone(s),i=e.clone(o),r=e.clone(u)}.bind(this),function(){a(t,r,i)}.bind(this))}function Y(t){var n=e.clone(t),r=this,i=function(e){r.delete_text_label_data(Object.keys(t)),r.draw_everything()};i(t),this.undo_stack.push(function(){e.extend(r.text_labels,n),r.draw_these_text_labels(Object.keys(n)),t=e.clone(n)},function(){i(t)})}function Z(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function et(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function tt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function nt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function rt(){this.toggle_beziers(!0)}function it(){this.toggle_beziers(!1)}function st(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ot(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function ut(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function at(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function ft(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),W.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function lt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w)}function ct(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function ht(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function pt(e){this._zoom_extent(e,"nodes")}function dt(e){this._zoom_extent(e,"canvas")}function vt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function mt(){return this.zoom_container.get_size()}function gt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function yt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function wt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Et(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function St(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function xt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Tt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_none:z,select_selectable:X,select_metabolite_with_id:W,select_single_node:V,deselect_nodes:$,select_text_label:J,deselect_text_labels:K,new_reaction_from_scratch:ot,new_reaction_for_metabolite:ft,cycle_primary_node:lt,make_selected_node_primary:ct,extend_nodes:ut,extend_reactions:at,delete_selected:Q,delete_nodes:G,delete_text_labels:Y,delete_node_data:Z,delete_segment_data:et,delete_reaction_data:tt,delete_text_label_data:nt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:ht,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:st,hide_beziers:it,show_beziers:rt,zoom_extent_nodes:pt,zoom_extent_canvas:dt,_zoom_extent:vt,get_size:mt,zoom_to_reaction:gt,zoom_to_node:yt,highlight_reaction:bt,highlight_node:wt,highlight:Et,save:St,map_for_export:xt,save_svg:Tt},h}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("Input",["utils","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o){function a(e,s,u){var a=e.append("div").attr("id","rxn-input"),f=t(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.selection=a,this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(s instanceof n){this.map=s;var l=90;this.direction_arrow=new o(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s)}else console.error("Cannot set the map. It is not an instance of builder/Map");u instanceof r?(this.zoom_container=u,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new i,this.toggle(!1),this.target_coords=null}function f(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function l(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function c(){return this.selection.style("display")!="none"}function h(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.selection.style("display","none"),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function p(e){this.selection.style("display","block"),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function d(){this.selection.style("display","none"),this.completely.hideDropDown()}function v(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function m(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.selection.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px"),this.direction_arrow.set_location(e),this.direction_arrow.show()}function g(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function y(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sun, 27 Jul 2014 11:54:31 -0700 Subject: [PATCH 02/33] Invert selection; delete nodes and text labels together --- escher/js/src/Behavior.js | 2 +- escher/js/src/Builder.js | 12 +++- escher/js/src/Map.js | 104 +++++++++++++++------------ escher/lib/escher.1.0.0b2.js | 118 ++++++++++++++++++------------- escher/lib/escher.1.0.0b2.min.js | 2 +- 5 files changed, 135 insertions(+), 103 deletions(-) diff --git a/escher/js/src/Behavior.js b/escher/js/src/Behavior.js index 3819f3c7..f4369260 100644 --- a/escher/js/src/Behavior.js +++ b/escher/js/src/Behavior.js @@ -295,7 +295,7 @@ define(["utils", "build"], function(utils, build) { behavior.on("dragstart", function () { // silence other listeners - d3.event.sourceEvent.stopPropagation(); console.log('dragstart'); + d3.event.sourceEvent.stopPropagation(); // remember the total displacement for later // total_displacement = {}; total_displacement = {x: 0, y: 0}; diff --git a/escher/js/src/Builder.js b/escher/js/src/Builder.js index 126da44f..022054a7 100644 --- a/escher/js/src/Builder.js +++ b/escher/js/src/Builder.js @@ -371,8 +371,12 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba text: "Make primary metabolite (p)" }) .button({ key: keys.cycle_primary, text: "Cycle primary metabolite (c)" }) + .button({ key: keys.select_all, + text: "Select all (Ctrl a)" }) .button({ key: keys.select_none, - text: "Select none (Ctrl Shift a)" }); + text: "Select none (Ctrl Shift a)" }) + .button({ key: keys.invert_selection, + text: "Invert selection" }); } else { edit_menu.button({ key: keys.view_mode, id: 'view-mode-menu-button', @@ -672,9 +676,11 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba redo: { key: 90, modifiers: { control: true, shift: true }, target: map.undo_stack, fn: map.undo_stack.redo }, + select_all: { key: 65, modifiers: { control: true }, // Ctrl Shift a + fn: map.select_all.bind(map) }, select_none: { key: 65, modifiers: { control: true, shift: true }, // Ctrl Shift a - target: map, - fn: map.select_none }, + fn: map.select_none.bind(map) }, + invert_selection: { fn: map.invert_selection.bind(map) }, show_settings: { key: 188, modifiers: { control: true }, // Ctrl , fn: settings_page.toggle.bind(settings_page) } }); diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index 4c2778b3..787cf1e8 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -48,7 +48,9 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan set_metabolite_data: set_metabolite_data, clear_map: clear_map, // selection + select_all: select_all, select_none: select_none, + invert_selection: invert_selection, select_selectable: select_selectable, select_metabolite_with_id: select_metabolite_with_id, select_single_node: select_single_node, @@ -64,8 +66,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan extend_reactions: extend_reactions, // delete delete_selected: delete_selected, - delete_nodes: delete_nodes, - delete_text_labels: delete_text_labels, + delete_selectable: delete_selectable, delete_node_data: delete_node_data, delete_segment_data: delete_segment_data, delete_reaction_data: delete_reaction_data, @@ -836,7 +837,9 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan self = this; this.sel.select('#nodes') .selectAll('.selected') - .each(function(d) { selected_nodes[d.node_id] = self.nodes[d.node_id]; }); + .each(function(d) { + selected_nodes[d.node_id] = this.nodes[d.node_id]; + }.bind(this)); return selected_nodes; } function get_selected_text_label_ids() { @@ -851,20 +854,48 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan self = this; this.sel.select('#text-labels') .selectAll('.selected') - .each(function(d) { selected_text_labels[d.text_label_id] = self.text_labels[d.text_label_id]; }); + .each(function(d) { + selected_text_labels[d.text_label_id] = this.text_labels[d.text_label_id]; + }.bind(this)); return selected_text_labels; } + function select_all() { + /** Select all nodes and text labels. + + */ + this.sel.selectAll('#nodes,#text-labels') + .selectAll('.node,.text-label') + .classed('selected', true); + } + function select_none() { + /** Deselect all nodes and text labels. + + */ this.sel.selectAll('.selected') .classed('selected', false); } + function invert_selection() { + /** Invert selection of nodes and text labels. + + */ + var selection = this.sel.selectAll('#nodes,#text-labels') + .selectAll('.node,.text-label'); + selection.classed('selected', function() { + return !d3.select(this).classed('selected'); + }); + } + function select_metabolite_with_id(node_id) { /** Select a metabolite with the given id, and turn off the reaction target. */ + // deselect all text labels + this.deselect_text_labels(); + var node_selection = this.sel.select('#nodes').selectAll('.node'), coords, selected_node; @@ -964,15 +995,13 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan Undoable. */ - var selected_nodes = this.get_selected_nodes(); - if (Object.keys(selected_nodes).length >= 1) - this.delete_nodes(selected_nodes); - - var selected_text_labels = this.get_selected_text_labels(); - if (Object.keys(selected_text_labels).length >= 1) - this.delete_text_labels(selected_text_labels); + var selected_nodes = this.get_selected_nodes(), + selected_text_labels = this.get_selected_text_labels(); + if (Object.keys(selected_nodes).length >= 1 || + Object.keys(selected_text_labels).length >= 1) + this.delete_selectable(selected_nodes, selected_text_labels); } - function delete_nodes(selected_nodes) { + function delete_selectable(selected_nodes, selected_text_labels) { /** Delete the nodes and associated segments and reactions. Undoable. @@ -986,11 +1015,14 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan var saved_nodes = utils.clone(selected_nodes), saved_segment_objs_w_segments = utils.clone(segment_objs_w_segments), saved_reactions = utils.clone(reactions), - delete_and_draw = function(nodes, reactions, segment_objs) { + saved_text_labels = utils.clone(selected_text_labels), + delete_and_draw = function(nodes, reactions, segment_objs, + selected_text_labels) { // delete nodes, segments, and reactions with no segments this.delete_node_data(Object.keys(selected_nodes)); this.delete_segment_data(segment_objs); this.delete_reaction_data(Object.keys(reactions)); + this.delete_text_label_data(Object.keys(selected_text_labels)); // apply the reaction and node data if (this.has_reaction_data()) @@ -999,12 +1031,12 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.apply_metabolite_data_domain(); // redraw - // TODO just redraw these nodes and segments + // TODO just redraw these nodes, segments, and labels this.draw_everything(); }.bind(this); // delete - delete_and_draw(selected_nodes, reactions, segment_objs_w_segments); + delete_and_draw(selected_nodes, reactions, segment_objs_w_segments, selected_text_labels); // add to undo/redo stack this.undo_stack.push(function() { @@ -1049,6 +1081,12 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.draw_these_nodes(Object.keys(saved_nodes)); } + // redraw the saved text_labels + utils.extend(this.text_labels, saved_text_labels); + this.draw_these_text_labels(Object.keys(saved_text_labels)); + // copy text_labels to re-delete + selected_text_labels = utils.clone(saved_text_labels); + // copy nodes to re-delete selected_nodes = utils.clone(saved_nodes); segment_objs_w_segments = utils.clone(saved_segment_objs_w_segments); @@ -1056,41 +1094,11 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan }.bind(this), function () { // redo // clone the nodes and reactions, to redo this action later - delete_and_draw(selected_nodes, reactions, segment_objs_w_segments); + delete_and_draw(selected_nodes, reactions, segment_objs_w_segments, + selected_text_labels); }.bind(this)); } - function delete_text_labels(selected_text_labels) { - /** Delete the text_labels. - - Undoable. - - */ - // copy text_labels to undelete - var saved_text_labels = utils.clone(selected_text_labels), - self = this, - delete_and_draw = function(text_labels) { - // delete text_labels, segments, and reactions with no segments - self.delete_text_label_data(Object.keys(selected_text_labels)); - // redraw - // TODO just redraw these text_labels - self.draw_everything(); - }; - // delete - delete_and_draw(selected_text_labels); - - // add to undo/redo stack - this.undo_stack.push(function() { // undo - // redraw the saved text_labels, reactions, and segments - utils.extend(self.text_labels, saved_text_labels); - self.draw_these_text_labels(Object.keys(saved_text_labels)); - // copy text_labels to re-delete - selected_text_labels = utils.clone(saved_text_labels); - }, function () { // redo - // clone the text_labels - delete_and_draw(selected_text_labels); - }); - } function delete_node_data(node_ids) { /** Delete nodes, and remove from search index. */ @@ -1103,6 +1111,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan delete this.nodes[node_id]; }.bind(this)); } + function delete_segment_data(segment_objs) { /** Delete segments, and update connected_segments in nodes. Also deletes any reactions with 0 segments. @@ -1460,6 +1469,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.draw_these_reactions(reactions_to_draw); // 7. select the primary node this.select_metabolite_with_id(primary_node_id); + return null; } function make_selected_node_primary() { var selected_nodes = this.get_selected_nodes(), diff --git a/escher/lib/escher.1.0.0b2.js b/escher/lib/escher.1.0.0b2.js index 5a06d4e9..8053418f 100644 --- a/escher/lib/escher.1.0.0b2.js +++ b/escher/lib/escher.1.0.0b2.js @@ -3100,7 +3100,7 @@ define('Behavior',["utils", "build"], function(utils, build) { behavior.on("dragstart", function () { // silence other listeners - d3.event.sourceEvent.stopPropagation(); console.log('dragstart'); + d3.event.sourceEvent.stopPropagation(); // remember the total displacement for later // total_displacement = {}; total_displacement = {x: 0, y: 0}; @@ -7257,7 +7257,9 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb set_metabolite_data: set_metabolite_data, clear_map: clear_map, // selection + select_all: select_all, select_none: select_none, + invert_selection: invert_selection, select_selectable: select_selectable, select_metabolite_with_id: select_metabolite_with_id, select_single_node: select_single_node, @@ -7273,8 +7275,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb extend_reactions: extend_reactions, // delete delete_selected: delete_selected, - delete_nodes: delete_nodes, - delete_text_labels: delete_text_labels, + delete_selectable: delete_selectable, delete_node_data: delete_node_data, delete_segment_data: delete_segment_data, delete_reaction_data: delete_reaction_data, @@ -8045,7 +8046,9 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb self = this; this.sel.select('#nodes') .selectAll('.selected') - .each(function(d) { selected_nodes[d.node_id] = self.nodes[d.node_id]; }); + .each(function(d) { + selected_nodes[d.node_id] = this.nodes[d.node_id]; + }.bind(this)); return selected_nodes; } function get_selected_text_label_ids() { @@ -8060,20 +8063,48 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb self = this; this.sel.select('#text-labels') .selectAll('.selected') - .each(function(d) { selected_text_labels[d.text_label_id] = self.text_labels[d.text_label_id]; }); + .each(function(d) { + selected_text_labels[d.text_label_id] = this.text_labels[d.text_label_id]; + }.bind(this)); return selected_text_labels; } + function select_all() { + /** Select all nodes and text labels. + + */ + this.sel.selectAll('#nodes,#text-labels') + .selectAll('.node,.text-label') + .classed('selected', true); + } + function select_none() { + /** Deselect all nodes and text labels. + + */ this.sel.selectAll('.selected') .classed('selected', false); } + function invert_selection() { + /** Invert selection of nodes and text labels. + + */ + var selection = this.sel.selectAll('#nodes,#text-labels') + .selectAll('.node,.text-label'); + selection.classed('selected', function() { + return !d3.select(this).classed('selected'); + }); + } + function select_metabolite_with_id(node_id) { /** Select a metabolite with the given id, and turn off the reaction target. */ + // deselect all text labels + this.deselect_text_labels(); + var node_selection = this.sel.select('#nodes').selectAll('.node'), coords, selected_node; @@ -8173,15 +8204,13 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb Undoable. */ - var selected_nodes = this.get_selected_nodes(); - if (Object.keys(selected_nodes).length >= 1) - this.delete_nodes(selected_nodes); - - var selected_text_labels = this.get_selected_text_labels(); - if (Object.keys(selected_text_labels).length >= 1) - this.delete_text_labels(selected_text_labels); + var selected_nodes = this.get_selected_nodes(), + selected_text_labels = this.get_selected_text_labels(); + if (Object.keys(selected_nodes).length >= 1 || + Object.keys(selected_text_labels).length >= 1) + this.delete_selectable(selected_nodes, selected_text_labels); } - function delete_nodes(selected_nodes) { + function delete_selectable(selected_nodes, selected_text_labels) { /** Delete the nodes and associated segments and reactions. Undoable. @@ -8195,11 +8224,14 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb var saved_nodes = utils.clone(selected_nodes), saved_segment_objs_w_segments = utils.clone(segment_objs_w_segments), saved_reactions = utils.clone(reactions), - delete_and_draw = function(nodes, reactions, segment_objs) { + saved_text_labels = utils.clone(selected_text_labels), + delete_and_draw = function(nodes, reactions, segment_objs, + selected_text_labels) { // delete nodes, segments, and reactions with no segments this.delete_node_data(Object.keys(selected_nodes)); this.delete_segment_data(segment_objs); this.delete_reaction_data(Object.keys(reactions)); + this.delete_text_label_data(Object.keys(selected_text_labels)); // apply the reaction and node data if (this.has_reaction_data()) @@ -8208,12 +8240,12 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb this.apply_metabolite_data_domain(); // redraw - // TODO just redraw these nodes and segments + // TODO just redraw these nodes, segments, and labels this.draw_everything(); }.bind(this); // delete - delete_and_draw(selected_nodes, reactions, segment_objs_w_segments); + delete_and_draw(selected_nodes, reactions, segment_objs_w_segments, selected_text_labels); // add to undo/redo stack this.undo_stack.push(function() { @@ -8258,6 +8290,12 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb this.draw_these_nodes(Object.keys(saved_nodes)); } + // redraw the saved text_labels + utils.extend(this.text_labels, saved_text_labels); + this.draw_these_text_labels(Object.keys(saved_text_labels)); + // copy text_labels to re-delete + selected_text_labels = utils.clone(saved_text_labels); + // copy nodes to re-delete selected_nodes = utils.clone(saved_nodes); segment_objs_w_segments = utils.clone(saved_segment_objs_w_segments); @@ -8265,41 +8303,11 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb }.bind(this), function () { // redo // clone the nodes and reactions, to redo this action later - delete_and_draw(selected_nodes, reactions, segment_objs_w_segments); + delete_and_draw(selected_nodes, reactions, segment_objs_w_segments, + selected_text_labels); }.bind(this)); } - function delete_text_labels(selected_text_labels) { - /** Delete the text_labels. - - Undoable. - - */ - // copy text_labels to undelete - var saved_text_labels = utils.clone(selected_text_labels), - self = this, - delete_and_draw = function(text_labels) { - // delete text_labels, segments, and reactions with no segments - self.delete_text_label_data(Object.keys(selected_text_labels)); - // redraw - // TODO just redraw these text_labels - self.draw_everything(); - }; - - // delete - delete_and_draw(selected_text_labels); - // add to undo/redo stack - this.undo_stack.push(function() { // undo - // redraw the saved text_labels, reactions, and segments - utils.extend(self.text_labels, saved_text_labels); - self.draw_these_text_labels(Object.keys(saved_text_labels)); - // copy text_labels to re-delete - selected_text_labels = utils.clone(saved_text_labels); - }, function () { // redo - // clone the text_labels - delete_and_draw(selected_text_labels); - }); - } function delete_node_data(node_ids) { /** Delete nodes, and remove from search index. */ @@ -8312,6 +8320,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb delete this.nodes[node_id]; }.bind(this)); } + function delete_segment_data(segment_objs) { /** Delete segments, and update connected_segments in nodes. Also deletes any reactions with 0 segments. @@ -8669,6 +8678,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb this.draw_these_reactions(reactions_to_draw); // 7. select the primary node this.select_metabolite_with_id(primary_node_id); + return null; } function make_selected_node_primary() { var selected_nodes = this.get_selected_nodes(), @@ -11007,8 +11017,12 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush text: "Make primary metabolite (p)" }) .button({ key: keys.cycle_primary, text: "Cycle primary metabolite (c)" }) + .button({ key: keys.select_all, + text: "Select all (Ctrl a)" }) .button({ key: keys.select_none, - text: "Select none (Ctrl Shift a)" }); + text: "Select none (Ctrl Shift a)" }) + .button({ key: keys.invert_selection, + text: "Invert selection" }); } else { edit_menu.button({ key: keys.view_mode, id: 'view-mode-menu-button', @@ -11308,9 +11322,11 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush redo: { key: 90, modifiers: { control: true, shift: true }, target: map.undo_stack, fn: map.undo_stack.redo }, + select_all: { key: 65, modifiers: { control: true }, // Ctrl Shift a + fn: map.select_all.bind(map) }, select_none: { key: 65, modifiers: { control: true, shift: true }, // Ctrl Shift a - target: map, - fn: map.select_none }, + fn: map.select_none.bind(map) }, + invert_selection: { fn: map.invert_selection.bind(map) }, show_settings: { key: 188, modifiers: { control: true }, // Ctrl , fn: settings_page.toggle.bind(settings_page) } }); diff --git a/escher/lib/escher.1.0.0b2.min.js b/escher/lib/escher.1.0.0b2.min.js index 60bc4bbc..35ae099d 100644 --- a/escher/lib/escher.1.0.0b2.min.js +++ b/escher/lib/escher.1.0.0b2.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label").style("cursor","default")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label").style("cursor","default")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("text").attr("class","text-label label").style("cursor","default").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function f(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function l(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),console.log("dragstart"),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("text-label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("text-label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="text-label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="text-label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function c(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function h(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function v(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_selectable_drag:a,toggle_label_drag:f,get_selectable_drag:l,get_bezier_drag:c,get_reaction_label_drag:h,get_node_label_drag:p,get_generic_drag:d,get_generic_angular_drag:v},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.selectable_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(n){e[n.node_id]=t.nodes[n.node_id]}),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(n){e[n.text_label_id]=t.text_labels[n.text_label_id]}),e}function z(){this.sel.selectAll(".selected").classed("selected",!1)}function W(e){var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function X(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function V(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function $(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function J(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function K(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Q(){var e=this.get_selected_nodes();Object.keys(e).length>=1&&this.delete_nodes(e);var t=this.get_selected_text_labels();Object.keys(t).length>=1&&this.delete_text_labels(t)}function G(t){var n=this.segments_and_reactions_for_nodes(t),r=n.reactions,i=n.segment_objs_w_segments,s=e.clone(t),o=e.clone(i),u=e.clone(r),a=function(e,n,r){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);a(t,r,i),this.undo_stack.push(function(){this.extend_nodes(s),this.extend_reactions(u);var n=Object.keys(u);o.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in s)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),n.indexOf(e.reaction_id)==-1&&n.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var a=this.update_reaction_data_domain();a?this.draw_all_reactions():this.draw_these_reactions(n)}else this.draw_these_reactions(n);if(this.has_metabolite_data()){var a=this.update_metabolite_data_domain();a?this.draw_all_nodes():this.draw_these_nodes(Object.keys(s))}else this.draw_these_nodes(Object.keys(s));t=e.clone(s),i=e.clone(o),r=e.clone(u)}.bind(this),function(){a(t,r,i)}.bind(this))}function Y(t){var n=e.clone(t),r=this,i=function(e){r.delete_text_label_data(Object.keys(t)),r.draw_everything()};i(t),this.undo_stack.push(function(){e.extend(r.text_labels,n),r.draw_these_text_labels(Object.keys(n)),t=e.clone(n)},function(){i(t)})}function Z(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function et(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function tt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function nt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function rt(){this.toggle_beziers(!0)}function it(){this.toggle_beziers(!1)}function st(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ot(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function ut(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function at(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function ft(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),W.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function lt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w)}function ct(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function ht(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function pt(e){this._zoom_extent(e,"nodes")}function dt(e){this._zoom_extent(e,"canvas")}function vt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function mt(){return this.zoom_container.get_size()}function gt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function yt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function wt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Et(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function St(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function xt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Tt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_none:z,select_selectable:X,select_metabolite_with_id:W,select_single_node:V,deselect_nodes:$,select_text_label:J,deselect_text_labels:K,new_reaction_from_scratch:ot,new_reaction_for_metabolite:ft,cycle_primary_node:lt,make_selected_node_primary:ct,extend_nodes:ut,extend_reactions:at,delete_selected:Q,delete_nodes:G,delete_text_labels:Y,delete_node_data:Z,delete_segment_data:et,delete_reaction_data:tt,delete_text_label_data:nt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:ht,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:st,hide_beziers:it,show_beziers:rt,zoom_extent_nodes:pt,zoom_extent_canvas:dt,_zoom_extent:vt,get_size:mt,zoom_to_reaction:gt,zoom_to_node:yt,highlight_reaction:bt,highlight_node:wt,highlight:Et,save:St,map_for_export:xt,save_svg:Tt},h}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("Input",["utils","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o){function a(e,s,u){var a=e.append("div").attr("id","rxn-input"),f=t(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.selection=a,this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(s instanceof n){this.map=s;var l=90;this.direction_arrow=new o(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s)}else console.error("Cannot set the map. It is not an instance of builder/Map");u instanceof r?(this.zoom_container=u,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new i,this.toggle(!1),this.target_coords=null}function f(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function l(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function c(){return this.selection.style("display")!="none"}function h(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.selection.style("display","none"),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function p(e){this.selection.style("display","block"),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function d(){this.selection.style("display","none"),this.completely.hideDropDown()}function v(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function m(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.selection.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px"),this.direction_arrow.set_location(e),this.direction_arrow.show()}function g(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function y(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label").style("cursor","default")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label").style("cursor","default")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("text").attr("class","text-label label").style("cursor","default").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function f(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function l(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("text-label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("text-label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="text-label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="text-label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function c(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function h(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function v(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_selectable_drag:a,toggle_label_drag:f,get_selectable_drag:l,get_bezier_drag:c,get_reaction_label_drag:h,get_node_label_drag:p,get_generic_drag:d,get_generic_angular_drag:v},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.selectable_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t)}function Z(t,n){var r=this.segments_and_reactions_for_nodes(t),i=r.reactions,s=r.segment_objs_w_segments,o=e.clone(t),u=e.clone(s),a=e.clone(i),f=e.clone(n),l=function(e,n,r,i){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(i)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);l(t,i,s,n),this.undo_stack.push(function(){this.extend_nodes(o),this.extend_reactions(a);var r=Object.keys(a);u.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in o)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),r.indexOf(e.reaction_id)==-1&&r.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var l=this.update_reaction_data_domain();l?this.draw_all_reactions():this.draw_these_reactions(r)}else this.draw_these_reactions(r);if(this.has_metabolite_data()){var l=this.update_metabolite_data_domain();l?this.draw_all_nodes():this.draw_these_nodes(Object.keys(o))}else this.draw_these_nodes(Object.keys(o));e.extend(this.text_labels,f),this.draw_these_text_labels(Object.keys(f)),n=e.clone(f),t=e.clone(o),s=e.clone(u),i=e.clone(a)}.bind(this),function(){l(t,i,s,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ct(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function ht(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function pt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function dt(e){this._zoom_extent(e,"nodes")}function vt(e){this._zoom_extent(e,"canvas")}function mt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function gt(){return this.zoom_container.get_size()}function yt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function Et(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function St(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function xt(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function Tt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Nt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:lt,cycle_primary_node:ct,make_selected_node_primary:ht,extend_nodes:at,extend_reactions:ft,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:pt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:dt,zoom_extent_canvas:vt,_zoom_extent:mt,get_size:gt,zoom_to_reaction:yt,zoom_to_node:bt,highlight_reaction:wt,highlight_node:Et,highlight:St,save:xt,map_for_export:Tt,save_svg:Nt},h}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("Input",["utils","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o){function a(e,s,u){var a=e.append("div").attr("id","rxn-input"),f=t(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.selection=a,this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(s instanceof n){this.map=s;var l=90;this.direction_arrow=new o(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s)}else console.error("Cannot set the map. It is not an instance of builder/Map");u instanceof r?(this.zoom_container=u,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new i,this.toggle(!1),this.target_coords=null}function f(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function l(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function c(){return this.selection.style("display")!="none"}function h(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.selection.style("display","none"),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function p(e){this.selection.style("display","block"),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function d(){this.selection.style("display","none"),this.completely.hideDropDown()}function v(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function m(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.selection.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px"),this.direction_arrow.set_location(e),this.direction_arrow.show()}function g(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function y(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Mon, 11 Aug 2014 10:07:10 -0700 Subject: [PATCH 03/33] Composed PlacedDiv for placement of HTML elements on SVG container. --- escher/css/builder-embed.css | 9 +- escher/js/src/Behavior.js | 45 +++++++- escher/js/src/{Input.js => BuildInput.js} | 129 +++++++++++----------- escher/js/src/Builder.js | 54 ++++++--- escher/js/src/Map.js | 4 +- escher/js/src/PlacedDiv.js | 59 ++++++++++ escher/js/src/TextEditInput.js | 23 ++++ escher/js/src/draw.js | 14 +-- 8 files changed, 243 insertions(+), 94 deletions(-) rename escher/js/src/{Input.js => BuildInput.js} (75%) create mode 100644 escher/js/src/PlacedDiv.js create mode 100644 escher/js/src/TextEditInput.js diff --git a/escher/css/builder-embed.css b/escher/css/builder-embed.css index a230175d..862f6534 100644 --- a/escher/css/builder-embed.css +++ b/escher/css/builder-embed.css @@ -19,12 +19,16 @@ fill: black; stroke: none; text-rendering: optimizelegibility; + cursor: default; } .reaction-label { fill: rgb(32, 32, 120); text-rendering: optimizelegibility; } -.text-label { +.text-label .label { + font-size: 50px; +} +.text-label-input { font-size: 50px; } .node-circle { @@ -100,4 +104,7 @@ .cursor-grabbing { cursor: grabbing; cursor: -webkit-grabbing; +} +.edit-text-cursor { + cursor: text; } \ No newline at end of file diff --git a/escher/js/src/Behavior.js b/escher/js/src/Behavior.js index f4369260..daca716e 100644 --- a/escher/js/src/Behavior.js +++ b/escher/js/src/Behavior.js @@ -27,9 +27,12 @@ define(["utils", "build"], function(utils, build) { toggle_rotation_mode: toggle_rotation_mode, turn_everything_on: turn_everything_on, turn_everything_off: turn_everything_off, + // toggle toggle_selectable_click: toggle_selectable_click, + toggle_text_label_edit: toggle_text_label_edit, toggle_selectable_drag: toggle_selectable_drag, toggle_label_drag: toggle_label_drag, + // get drag behaviors get_selectable_drag: get_selectable_drag, get_bezier_drag: get_bezier_drag, get_reaction_label_drag: get_reaction_label_drag, @@ -51,26 +54,27 @@ define(["utils", "build"], function(utils, build) { this.rotation_mode_enabled = false; this.rotation_drag = d3.behavior.drag(); - // init empty + // behaviors to be applied this.selectable_click = null; + this.text_label_click = null; + this.selectable_drag = this.empty_behavior; this.node_mouseover = null; this.node_mouseout = null; - this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; this.turn_everything_on(); } function turn_everything_on() { - /** Toggle everything except rotation mode. - + /** Toggle everything except rotation mode and text mode. + */ this.toggle_selectable_click(true); this.toggle_selectable_drag(true); this.toggle_label_drag(true); } function turn_everything_off() { - /** Toggle everything except rotation mode. + /** Toggle everything except rotation mode and text mode. */ this.toggle_selectable_click(false); @@ -242,6 +246,37 @@ define(["utils", "build"], function(utils, build) { } } + function toggle_text_label_edit(on_off) { + /** With no argument, toggle the text edit on click on/off. + + Pass in a boolean argument to set the on/off state. + + The backup state is equal to selectable_click. + + */ + if (on_off===undefined) on_off = this.text_edit_click==null; + if (on_off) { + var map = this.map, + selection = this.selection; + this.text_label_click = function() { + if (d3.event.defaultPrevented) return; // click suppressed + // run the callback + var coords_a = d3.transform(d3.select(this).attr('transform')).translate, + coords = {x: coords_a[0], y: coords_a[1]}; + map.callback_manager.run('edit_text_label', coords); + d3.event.stopPropagation(); + }; + this.map.sel.select('#text-labels') + .selectAll('.label') + .classed('edit-text-cursor', true); + } else { + this.text_label_click = this.selectable_click; + this.map.sel.select('#text-labels') + .selectAll('.label') + .classed('edit-text-cursor', false); + } + } + function toggle_selectable_drag(on_off) { /** With no argument, toggle the node drag & bezier drag on or off. diff --git a/escher/js/src/Input.js b/escher/js/src/BuildInput.js similarity index 75% rename from escher/js/src/Input.js rename to escher/js/src/BuildInput.js index 11fccfe5..fb66eb12 100644 --- a/escher/js/src/Input.js +++ b/escher/js/src/BuildInput.js @@ -1,42 +1,42 @@ -define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", "draw", "DirectionArrow"], function(utils, completely, Map, ZoomContainer, CallbackManager, draw, DirectionArrow) { +define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'CallbackManager', 'draw', 'DirectionArrow'], function(utils, PlacedDiv, completely, Map, ZoomContainer, CallbackManager, draw, DirectionArrow) { /** */ - var Input = utils.make_class(); + var BuildInput = utils.make_class(); // instance methods - Input.prototype = { init: init, - setup_map_callbacks: setup_map_callbacks, - setup_zoom_callbacks: setup_zoom_callbacks, - is_visible: is_visible, - toggle: toggle, - show_dropdown: show_dropdown, - hide_dropdown: hide_dropdown, - place_at_selected: place_at_selected, - place: place, - reload_at_selected: reload_at_selected, - reload: reload, - toggle_start_reaction_listener: toggle_start_reaction_listener, - hide_target: hide_target, - show_target: show_target }; + BuildInput.prototype = { init: init, + setup_map_callbacks: setup_map_callbacks, + setup_zoom_callbacks: setup_zoom_callbacks, + is_visible: is_visible, + toggle: toggle, + show_dropdown: show_dropdown, + hide_dropdown: hide_dropdown, + place_at_selected: place_at_selected, + place: place, + reload_at_selected: reload_at_selected, + reload: reload, + toggle_start_reaction_listener: toggle_start_reaction_listener, + hide_target: hide_target, + show_target: show_target }; - return Input; + return BuildInput; // definitions function init(selection, map, zoom_container) { // set up container - var new_sel = selection.append("div").attr("id", "rxn-input"); + var new_sel = selection.append('div').attr('id', 'rxn-input'); + this.placed_div = PlacedDiv(new_sel); // set up complete.ly - var c = completely(new_sel.node(), { backgroundColor: "#eee" }); + var c = completely(new_sel.node(), { backgroundColor: '#eee' }); d3.select(c.input) // .attr('placeholder', 'Reaction ID -- Flux') .on('input', function() { this.value = this.value - // .replace("/","") + // .replace("/","") .replace(" ","") .replace("\\","") .replace("<",""); }); - this.selection = new_sel; this.completely = c; // close button new_sel.append('button').attr('class', "button input-close-button") @@ -97,9 +97,11 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", } }.bind(this)); } + function is_visible() { - return this.selection.style('display') != 'none'; + return this.placed_div.is_visible(); } + function toggle(on_off) { if (on_off===undefined) this.is_active = !this.is_active; else this.is_active = on_off; @@ -114,7 +116,7 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", .add_escape_listener(function() { this.hide_dropdown(); }.bind(this)); } else { this.toggle_start_reaction_listener(false); - this.selection.style("display", "none"); + this.placed_div.hide(); this.completely.input.blur(); this.completely.hideDropDown(); this.map.set_status(null); @@ -125,14 +127,14 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", } } function show_dropdown(coords) { - this.selection.style("display", "block"); + this.placed_selection.show(); this.completely.input.blur(); this.completely.repaint(); this.completely.setText(""); this.completely.input.focus(); } function hide_dropdown() { - this.selection.style("display", "none"); + this.placed_selection.hide(); this.completely.hideDropDown(); } function place_at_selected() { @@ -148,20 +150,21 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", this.place(coords); } function place(coords) { - var d = {x: 240, y: 0}, - window_translate = this.map.zoom_container.window_translate, - window_scale = this.map.zoom_container.window_scale, - map_size = this.map.get_size(); - var left = Math.max(20, - Math.min(map_size.width - 270, - (window_scale * coords.x + window_translate.x - d.x))); - var top = Math.max(20, - Math.min(map_size.height - 40, - (window_scale * coords.y + window_translate.y - d.y))); - this.selection.style('position', 'absolute') - .style('display', 'block') - .style('left',left+'px') - .style('top',top+'px'); + this.placed_selection.place(coords); + // var d = {x: 240, y: 0}, + // window_translate = this.map.zoom_container.window_translate, + // window_scale = this.map.zoom_container.window_scale, + // map_size = this.map.get_size(); + // var left = Math.max(20, + // Math.min(map_size.width - 270, + // (window_scale * coords.x + window_translate.x - d.x))); + // var top = Math.max(20, + // Math.min(map_size.height - 40, + // (window_scale * coords.y + window_translate.y - d.y))); + // this.selection.style('position', 'absolute') + // .style('display', 'block') + // .style('left',left+'px') + // .style('top',top+'px'); this.direction_arrow.set_location(coords); this.direction_arrow.show(); @@ -278,12 +281,12 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", if (x.string.toLowerCase()==text.toLowerCase()) { if (starting_from_scratch) { map.new_reaction_from_scratch(x.reaction_abbreviation, - coords, - direction_arrow.get_rotation()); + coords, + direction_arrow.get_rotation()); } else { map.new_reaction_for_metabolite(x.reaction_abbreviation, - selected_node.node_id, - direction_arrow.get_rotation()); + selected_node.node_id, + direction_arrow.get_rotation()); } } }); @@ -312,26 +315,26 @@ define(["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", this.start_reaction_listener = on_off; if (this.start_reaction_listener) {; - this.map.sel.on('click.start_reaction', function(node) { - // TODO fix this hack - if (this.direction_arrow.dragging) return; - // reload the reaction input - var coords = { x: d3.mouse(node)[0], - y: d3.mouse(node)[1] }; - // unselect metabolites - this.map.deselect_nodes(); - this.map.deselect_text_labels(); - // reload the reaction input - this.reload(null, coords, true); - // generate the target symbol - this.show_target(this.map, coords); - }.bind(this, this.map.sel.node())); - this.map.sel.classed('start-reaction-cursor', true); - } else { - this.map.sel.on('click.start_reaction', null); - this.map.sel.classed('start-reaction-cursor', false); - this.hide_target(); - } + this.map.sel.on('click.start_reaction', function(node) { + // TODO fix this hack + if (this.direction_arrow.dragging) return; + // reload the reaction input + var coords = { x: d3.mouse(node)[0], + y: d3.mouse(node)[1] }; + // unselect metabolites + this.map.deselect_nodes(); + this.map.deselect_text_labels(); + // reload the reaction input + this.reload(null, coords, true); + // generate the target symbol + this.show_target(this.map, coords); + }.bind(this, this.map.sel.node())); + this.map.sel.classed('start-reaction-cursor', true); + } else { + this.map.sel.on('click.start_reaction', null); + this.map.sel.classed('start-reaction-cursor', false); + this.hide_target(); + } } function hide_target() { diff --git a/escher/js/src/Builder.js b/escher/js/src/Builder.js index 022054a7..5b3765ba 100644 --- a/escher/js/src/Builder.js +++ b/escher/js/src/Builder.js @@ -1,4 +1,4 @@ -define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "CallbackManager", "ui", "SearchBar", "Settings", "SettingsBar"], function(utils, Input, ZoomContainer, Map, CobraModel, Brush, CallbackManager, ui, SearchBar, Settings, SettingsBar) { +define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'CallbackManager', 'ui', 'SearchBar', 'Settings', 'SettingsBar', 'TextEditInput'], function(utils, BuildInput, ZoomContainer, Map, CobraModel, Brush, CallbackManager, ui, SearchBar, Settings, SettingsBar, TextEditInput) { /** A Builder object contains all the ui and logic to generate a map builder or viewer. Builder(options) @@ -15,6 +15,7 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba brush_mode: brush_mode, zoom_mode: zoom_mode, rotate_mode: rotate_mode, + text_mode: text_mode, _toggle_direction_buttons: _toggle_direction_buttons, _setup_menu: _setup_menu, _setup_simple_zoom_buttons: _setup_simple_zoom_buttons, @@ -180,8 +181,12 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba } // set up the reaction input with complete.ly - this.reaction_input = Input(this.options.selection, this.map, - this.zoom_container); + this.reaction_input = BuildInput(this.options.selection, this.map, + this.zoom_container); + + // set up the text edit input + this.text_edit_input = TextEditInput(this.options.selection, this.map, + this.zoom_container); // set up the Brush this.brush = new Brush(zoomed_sel, false, this.map, '.canvas-group'); @@ -218,7 +223,7 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba this.map.key_manager.assigned_keys = keys; // tell the key manager about the reaction input and search bar this.map.key_manager.input_list = [this.reaction_input, this.search_bar, - this.settings_page]; + this.settings_page, this.text_edit_input]; // make sure the key manager remembers all those changes this.map.key_manager.update(); // turn it on/off @@ -277,7 +282,9 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba this.map.behavior.toggle_selectable_click(mode=='build' || mode=='brush' || mode=='rotate'); this.map.behavior.toggle_selectable_drag(mode=='brush' || mode=='rotate'); this.map.behavior.toggle_label_drag(mode=='brush'); - if (mode=='view') + this.map.behavior.toggle_text_label_edit(mode=='text'); + // edit selections + if (mode=='view' || mode=='text') this.map.select_none(); if (mode=='rotate') this.map.deselect_text_labels(); @@ -302,6 +309,10 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba function rotate_mode() { this.callback_manager.run('rotate_mode'); this.set_mode('rotate'); + } + function text_mode() { + this.callback_manager.run('text_mode'); + this.set_mode('text'); } function _setup_menu(menu_selection, button_selection, map, zoom_container, key_manager, keys, enable_editing) { @@ -359,6 +370,9 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba .button({ key: keys.rotate_mode, id: 'rotate-mode-menu-button', text: "Rotate mode (r)" }) + .button({ key: keys.text_mode, + id: 'text-mode-menu-button', + text: "Text mode (t)" }) .divider() .button({ key: keys.delete, // icon: "glyphicon glyphicon-trash", @@ -446,7 +460,11 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba .button({ key: keys.rotate_mode, id: 'rotate-mode-button', icon: "glyphicon glyphicon-repeat", - tooltip: "Rotate mode (r)" }); + tooltip: "Rotate mode (r)" }) + .button({ key: keys.text_mode, + id: 'text-mode-button', + icon: "glyphicon glyphicon-font", + tooltip: "Text mode (r)" }); // arrow buttons this.direction_buttons = button_panel.append('li'); @@ -471,7 +489,8 @@ define(["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "Callba '#zoom-mode-menu-button', '#brush-mode-menu-button', '#rotate-mode-menu-button', - '#view-mode-menu-button']; + '#view-mode-menu-button', + '#text-mode-menu-button']; for (var i=0, l=ids.length; i Date: Mon, 11 Aug 2014 11:17:43 -0700 Subject: [PATCH 04/33] citing escher FAQ --- escher/css/index.css | 5 +++++ escher/templates/index.html | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/escher/css/index.css b/escher/css/index.css index d112778a..3b6b1202 100644 --- a/escher/css/index.css +++ b/escher/css/index.css @@ -5,6 +5,11 @@ body { /* The html and body elements cannot have any padding or margin. */ } +body { + font-size: 15px; + color: #585858; +} + /* Wrapper for page content to push down footer */ main { /* Negative indent footer by it's height */ diff --git a/escher/templates/index.html b/escher/templates/index.html index 12f426b1..5da7ac3e 100644 --- a/escher/templates/index.html +++ b/escher/templates/index.html @@ -47,6 +47,16 @@

Options

+ +
+

FAQ

+
    +
  1. How do I cite Escher?

    +

    Escher has not yet been published in a peer-review journal, but, in + the meantime, you can cite the code by DOI: [Fill in for release v1].

    +
  2. +
+
From af2d7e5e49ce6b992b010addbb44f79bc829a5a3 Mon Sep 17 00:00:00 2001 From: Zak King Date: Mon, 11 Aug 2014 11:49:01 -0700 Subject: [PATCH 05/33] Moved to beta 3; took cofactors out of cobra model json. --- escher/js/src/CobraModel.js | 13 +- .../{escher.1.0.0b2.js => escher.1.0.0b3.js} | 1311 +++++++++-------- ...r.1.0.0b2.min.js => escher.1.0.0b3.min.js} | 2 +- escher/version.py | 2 +- setup.py | 8 +- spec/javascripts/CobraModelSpec.js | 13 +- spec/javascripts/support/jasmine.yml | 2 +- 7 files changed, 736 insertions(+), 615 deletions(-) rename escher/lib/{escher.1.0.0b2.js => escher.1.0.0b3.js} (97%) rename escher/lib/{escher.1.0.0b2.min.js => escher.1.0.0b3.min.js} (53%) diff --git a/escher/js/src/CobraModel.js b/escher/js/src/CobraModel.js index db406914..d0ddbca3 100644 --- a/escher/js/src/CobraModel.js +++ b/escher/js/src/CobraModel.js @@ -32,17 +32,8 @@ define(["utils", "data_styles"], function(utils, data_styles) { delete this.metabolites[the_id].id; } - // get cofactors if preset - if ('cofactors' in model_data) { - if (model_data.cofactors instanceof Array) { - this.cofactors = model_data.cofactors; - } else { - console.warn('model_data.cofactors should be an array. Ignoring it'); - this.cofactors = []; - } - } else { - this.cofactors = []; - } + this.cofactors = ['atp', 'adp', 'nad', 'nadh', 'nadp', 'nadph', 'gtp', + 'gdp', 'h']; } function apply_reaction_data(reaction_data, styles) { diff --git a/escher/lib/escher.1.0.0b2.js b/escher/lib/escher.1.0.0b3.js similarity index 97% rename from escher/lib/escher.1.0.0b2.js rename to escher/lib/escher.1.0.0b3.js index 8053418f..f27cd5c3 100644 --- a/escher/lib/escher.1.0.0b2.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1326,412 +1326,6 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { } }); -/** - * complete.ly 1.0.0 - * MIT Licensing - * Copyright (c) 2013 Lorenzo Puccetti - * - * This Software shall be used for doing good things, not bad things. - * -**/ -define('lib/complete.ly',[],function() { -return function(container, config) { - config = config || {}; - config.fontSize = config.fontSize || '16px'; - config.fontFamily = config.fontFamily || 'sans-serif'; - config.promptInnerHTML = config.promptInnerHTML || ''; - config.color = config.color || '#333'; - config.hintColor = config.hintColor || '#aaa'; - config.backgroundColor = config.backgroundColor || '#fff'; - config.dropDownBorderColor = config.dropDownBorderColor || '#aaa'; - config.dropDownZIndex = config.dropDownZIndex || '100'; // to ensure we are in front of everybody - config.dropDownOnHoverBackgroundColor = config.dropDownOnHoverBackgroundColor || '#ddd'; - - var txtInput = document.createElement('input'); - txtInput.type ='text'; - txtInput.spellcheck = false; - txtInput.style.fontSize = config.fontSize; - txtInput.style.fontFamily = config.fontFamily; - txtInput.style.color = config.color; - txtInput.style.backgroundColor = config.backgroundColor; - txtInput.style.width = '100%'; - txtInput.style.outline = '0'; - txtInput.style.border = '0'; - txtInput.style.margin = '0'; - txtInput.style.padding = '0'; - - var txtHint = txtInput.cloneNode(); - txtHint.disabled=''; - txtHint.style.position = 'absolute'; - txtHint.style.top = '0'; - txtHint.style.left = '0'; - txtHint.style.borderColor = 'transparent'; - txtHint.style.boxShadow = 'none'; - txtHint.style.color = config.hintColor; - - txtInput.style.backgroundColor ='transparent'; - txtInput.style.verticalAlign = 'top'; - txtInput.style.position = 'relative'; - - var wrapper = document.createElement('div'); - wrapper.style.position = 'relative'; - wrapper.style.outline = '0'; - wrapper.style.border = '0'; - wrapper.style.margin = '0'; - wrapper.style.padding = '0'; - - var prompt = document.createElement('div'); - prompt.style.position = 'absolute'; - prompt.style.outline = '0'; - prompt.style.margin = '0'; - prompt.style.padding = '0'; - prompt.style.border = '0'; - prompt.style.fontSize = config.fontSize; - prompt.style.fontFamily = config.fontFamily; - prompt.style.color = config.color; - prompt.style.backgroundColor = config.backgroundColor; - prompt.style.top = '0'; - prompt.style.left = '0'; - prompt.style.overflow = 'hidden'; - prompt.innerHTML = config.promptInnerHTML; - prompt.style.background = 'transparent'; - if (document.body === undefined) { - throw 'document.body is undefined. The library was wired up incorrectly.'; - } - document.body.appendChild(prompt); - var w = prompt.getBoundingClientRect().right; // works out the width of the prompt. - wrapper.appendChild(prompt); - prompt.style.visibility = 'visible'; - prompt.style.left = '-'+w+'px'; - wrapper.style.marginLeft= w+'px'; - - wrapper.appendChild(txtHint); - wrapper.appendChild(txtInput); - - var dropDown = document.createElement('div'); - dropDown.style.position = 'absolute'; - dropDown.style.visibility = 'hidden'; - dropDown.style.outline = '0'; - dropDown.style.margin = '0'; - dropDown.style.padding = '0'; - dropDown.style.textAlign = 'left'; - dropDown.style.fontSize = config.fontSize; - dropDown.style.fontFamily = config.fontFamily; - dropDown.style.backgroundColor = config.backgroundColor; - dropDown.style.zIndex = config.dropDownZIndex; - dropDown.style.cursor = 'default'; - dropDown.style.borderStyle = 'solid'; - dropDown.style.borderWidth = '1px'; - dropDown.style.borderColor = config.dropDownBorderColor; - dropDown.style.overflowX= 'hidden'; - dropDown.style.whiteSpace = 'pre'; - dropDown.style.overflowY = 'scroll'; // note: this might be ugly when the scrollbar is not required. however in this way the width of the dropDown takes into account - - - var createDropDownController = function(elem) { - var rows = []; - var ix = 0; - var oldIndex = -1; - - var onMouseOver = function() { this.style.outline = '1px solid #ddd'; } - var onMouseOut = function() { this.style.outline = '0'; } - var onMouseDown = function() { p.hide(); p.onmouseselection(this.__hint); } - - var p = { - hide : function() { elem.style.visibility = 'hidden'; }, - refresh : function(token, array) { - elem.style.visibility = 'hidden'; - ix = 0; - elem.innerHTML =''; - var vph = (window.innerHeight || document.documentElement.clientHeight); - var rect = elem.parentNode.getBoundingClientRect(); - var distanceToTop = rect.top - 6; // heuristic give 6px - var distanceToBottom = vph - rect.bottom -6; // distance from the browser border. - - rows = []; - for (var i=0;i'+array[i].substring(token.length)+''; - rows.push(divRow); - elem.appendChild(divRow); - } - if (rows.length===0) { - return; // nothing to show. - } - if (rows.length===1 && token === rows[0].__hint) { - return; // do not show the dropDown if it has only one element which matches what we have just displayed. - } - - if (rows.length<2) return; - p.highlight(0); - - if (distanceToTop > distanceToBottom*3) { // Heuristic (only when the distance to the to top is 4 times more than distance to the bottom - elem.style.maxHeight = distanceToTop+'px'; // we display the dropDown on the top of the input text - elem.style.top =''; - elem.style.bottom ='100%'; - } else { - elem.style.top = '100%'; - elem.style.bottom = ''; - elem.style.maxHeight = distanceToBottom+'px'; - } - elem.style.visibility = 'visible'; - }, - highlight : function(index) { - if (oldIndex !=-1 && rows[oldIndex]) { - rows[oldIndex].style.backgroundColor = config.backgroundColor; - } - rows[index].style.backgroundColor = config.dropDownOnHoverBackgroundColor; // <-- should be config - oldIndex = index; - }, - move : function(step) { // moves the selection either up or down (unless it's not possible) step is either +1 or -1. - if (elem.style.visibility === 'hidden') return ''; // nothing to move if there is no dropDown. (this happens if the user hits escape and then down or up) - if (ix+step === -1 || ix+step === rows.length) return rows[ix].__hint; // NO CIRCULAR SCROLLING. - ix+=step; - p.highlight(ix); - return rows[ix].__hint;//txtShadow.value = uRows[uIndex].__hint ; - }, - onmouseselection : function() {} // it will be overwritten. - }; - return p; - } - - var dropDownController = createDropDownController(dropDown); - - dropDownController.onmouseselection = function(text) { - txtInput.value = txtHint.value = leftSide+text; - rs.onChange(txtInput.value); // <-- forcing it. - registerOnTextChangeOldValue = txtInput.value; // <-- ensure that mouse down will not show the dropDown now. - setTimeout(function() { txtInput.focus(); },0); // <-- I need to do this for IE - } - - wrapper.appendChild(dropDown); - container.appendChild(wrapper); - - var spacer; - var leftSide; // <-- it will contain the leftSide part of the textfield (the bit that was already autocompleted) - - - function calculateWidthForText(text) { - if (spacer === undefined) { // on first call only. - spacer = document.createElement('span'); - spacer.style.visibility = 'hidden'; - spacer.style.position = 'fixed'; - spacer.style.outline = '0'; - spacer.style.margin = '0'; - spacer.style.padding = '0'; - spacer.style.border = '0'; - spacer.style.left = '0'; - spacer.style.whiteSpace = 'pre'; - spacer.style.fontSize = config.fontSize; - spacer.style.fontFamily = config.fontFamily; - spacer.style.fontWeight = 'normal'; - document.body.appendChild(spacer); - } - - // Used to encode an HTML string into a plain text. - // taken from http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding - spacer.innerHTML = String(text).replace(/&/g, '&') - .replace(/"/g, '"') - .replace(/'/g, ''') - .replace(//g, '>'); - return spacer.getBoundingClientRect().right; - } - - - var rs = { - onArrowDown : function() {}, // defaults to no action. - onArrowUp : function() {}, // defaults to no action. - onEnter : function() {}, // defaults to no action. - onTab : function() {}, // defaults to no action. - onChange: function() { rs.repaint() }, // defaults to repainting. - startFrom: 0, - options: [], - wrapper : wrapper, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) - input : txtInput, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) - hint : txtHint, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) - dropDown : dropDown, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) - prompt : prompt, - setText : function(text) { - txtHint.value = text; - txtInput.value = text; - }, - getText : function() { - return txtInput.value; - }, - hideDropDown : function() { - dropDownController.hide(); - }, - repaint : function() { - var text = txtInput.value; - var startFrom = rs.startFrom; - var options = rs.options; - var optionsLength = options.length; - - // breaking text in leftSide and token. - var token = text.substring(startFrom); - leftSide = text.substring(0,startFrom); - - // updating the hint. - txtHint.value =''; - for (var i=0;i 0) { // if there is a hint - dropDownController.hide(); - txtInput.value = txtHint.value; - var hasTextChanged = registerOnTextChangeOldValue != txtInput.value - registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. - // for example imagine the array contains the following words: bee, beef, beetroot - // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) - if (hasTextChanged) { - rs.onChange(txtInput.value); // <-- forcing it. - } - } - return; - } - - if (keyCode == 13) { // enter (autocomplete triggered) - if (txtHint.value.length == 0) { // if there is a hint - rs.onEnter(); - } else { - var wasDropDownHidden = (dropDown.style.visibility == 'hidden'); - dropDownController.hide(); - - if (wasDropDownHidden) { - txtHint.value = txtInput.value; // ensure that no hint is left. - txtInput.focus(); - rs.onEnter(); - return; - } - - txtInput.value = txtHint.value; - var hasTextChanged = registerOnTextChangeOldValue != txtInput.value - registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. - // for example imagine the array contains the following words: bee, beef, beetroot - // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) - if (hasTextChanged) { - rs.onChange(txtInput.value); // <-- forcing it. - } - - } - return; - } - - if (keyCode == 40) { // down - var m = dropDownController.move(+1); - if (m == '') { rs.onArrowDown(); } - txtHint.value = leftSide+m; - return; - } - - if (keyCode == 38 ) { // up - var m = dropDownController.move(-1); - if (m == '') { rs.onArrowUp(); } - txtHint.value = leftSide+m; - e.preventDefault(); - e.stopPropagation(); - return; - } - - // it's important to reset the txtHint on key down. - // think: user presses a letter (e.g. 'x') and never releases... you get (xxxxxxxxxxxxxxxxx) - // and you would see still the hint - txtHint.value =''; // resets the txtHint. (it might be updated onKeyUp) - - }; - - if (txtInput.addEventListener) { - txtInput.addEventListener("keydown", keyDownHandler, false); - } else { // is this a fair assumption: that attachEvent will exist ? - txtInput.attachEvent('onkeydown', keyDownHandler); // IE<9 - } - return rs; -} -}); - define('data_styles',["utils"], function(utils) { return { import_and_check: import_and_check, text_for_data: text_for_data, @@ -1940,8 +1534,7 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { */ sel.append('text') - .attr('class', 'reaction-label label') - .style('cursor', 'default'); + .attr('class', 'reaction-label label'); // .on('mouseover', function(d) { // d3.select(this).style('stroke-width', String(3)+'px'); // d3.select(this.parentNode) @@ -2276,8 +1869,7 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { g.filter(function(d) { return d.node_type=='metabolite'; }) .append('text') - .attr('class', 'node-label label') - .style('cursor', 'default'); + .attr('class', 'node-label label'); } function update_node(update_selection, scale, has_metabolite_data, metabolite_data_styles, @@ -2343,9 +1935,10 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { function create_text_label(enter_selection) { utils.check_undefined(arguments, ['enter_selection']); - enter_selection.append('text') - .attr('class', 'text-label label') - .style('cursor', 'default') + enter_selection.append('g') + .attr('class', 'text-label') + .append('text') + .attr('class', 'label') .text(function(d) { return d.text; }); } @@ -2353,6 +1946,7 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { utils.check_undefined(arguments, ['update_selection', 'label_click', 'label_drag_behavior']); update_selection + .select('.label') .attr('transform', function(d) { return 'translate('+d.x+','+d.y+')';}) .on('click', label_click) .call(turn_off_drag) @@ -2832,9 +2426,12 @@ define('Behavior',["utils", "build"], function(utils, build) { toggle_rotation_mode: toggle_rotation_mode, turn_everything_on: turn_everything_on, turn_everything_off: turn_everything_off, + // toggle toggle_selectable_click: toggle_selectable_click, + toggle_text_label_edit: toggle_text_label_edit, toggle_selectable_drag: toggle_selectable_drag, toggle_label_drag: toggle_label_drag, + // get drag behaviors get_selectable_drag: get_selectable_drag, get_bezier_drag: get_bezier_drag, get_reaction_label_drag: get_reaction_label_drag, @@ -2856,26 +2453,27 @@ define('Behavior',["utils", "build"], function(utils, build) { this.rotation_mode_enabled = false; this.rotation_drag = d3.behavior.drag(); - // init empty + // behaviors to be applied this.selectable_click = null; + this.text_label_click = null; + this.selectable_drag = this.empty_behavior; this.node_mouseover = null; this.node_mouseout = null; - this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; this.turn_everything_on(); } function turn_everything_on() { - /** Toggle everything except rotation mode. - + /** Toggle everything except rotation mode and text mode. + */ this.toggle_selectable_click(true); this.toggle_selectable_drag(true); this.toggle_label_drag(true); } function turn_everything_off() { - /** Toggle everything except rotation mode. + /** Toggle everything except rotation mode and text mode. */ this.toggle_selectable_click(false); @@ -3047,6 +2645,37 @@ define('Behavior',["utils", "build"], function(utils, build) { } } + function toggle_text_label_edit(on_off) { + /** With no argument, toggle the text edit on click on/off. + + Pass in a boolean argument to set the on/off state. + + The backup state is equal to selectable_click. + + */ + if (on_off===undefined) on_off = this.text_edit_click==null; + if (on_off) { + var map = this.map, + selection = this.selection; + this.text_label_click = function() { + if (d3.event.defaultPrevented) return; // click suppressed + // run the callback + var coords_a = d3.transform(d3.select(this).attr('transform')).translate, + coords = {x: coords_a[0], y: coords_a[1]}; + map.callback_manager.run('edit_text_label', coords); + d3.event.stopPropagation(); + }; + this.map.sel.select('#text-labels') + .selectAll('.label') + .classed('edit-text-cursor', true); + } else { + this.text_label_click = this.selectable_click; + this.map.sel.select('#text-labels') + .selectAll('.label') + .classed('edit-text-cursor', false); + } + } + function toggle_selectable_drag(on_off) { /** With no argument, toggle the node drag & bezier drag on or off. @@ -7702,7 +7331,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb node_drag_behavior = this.behavior.selectable_drag, reaction_label_drag = this.behavior.reaction_label_drag, node_label_drag = this.behavior.node_label_drag, - text_label_click = this.behavior.selectable_click, + text_label_click = this.behavior.text_label_click, text_label_drag = this.behavior.selectable_drag, has_reaction_data = this.has_reaction_data(), reaction_data_styles = this.settings.data_styles['reaction'], @@ -7853,7 +7482,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb } function draw_these_text_labels(text_label_ids) { var text_labels = this.text_labels, - text_label_click = this.behavior.selectable_click, + text_label_click = this.behavior.text_label_click, text_label_drag = this.behavior.selectable_drag; // find text labels for text_label_ids @@ -8860,90 +8489,556 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb this.zoom_container.go_to(new_zoom, new_pos); } - function highlight_reaction(reaction_id) { - this.highlight(this.sel.selectAll('#r'+reaction_id).selectAll('text')); + function highlight_reaction(reaction_id) { + this.highlight(this.sel.selectAll('#r'+reaction_id).selectAll('text')); + } + function highlight_node(node_id) { + this.highlight(this.sel.selectAll('#n'+node_id).selectAll('text')); + } + function highlight(sel) { + this.sel.selectAll('.highlight') + .classed('highlight', false); + if (sel!==null) { + sel.classed('highlight', true); + } + } + + // ------------------------------------------------------------------------- + // IO + + function save() { + console.log("Saving"); + utils.download_json(this.map_for_export(), "saved_map"); + } + function map_for_export() { + var out = { reactions: utils.clone(this.reactions), + nodes: utils.clone(this.nodes), + membranes: utils.clone(this.membranes), + text_labels: utils.clone(this.text_labels), + canvas: this.canvas.size_and_location() }; + + // remove extra data + for (var r_id in out.reactions) { + var reaction = out.reactions[r_id]; + delete reaction.data; + delete reaction.data_string; + for (var s_id in reaction.segments) { + var segment = reaction.segments[s_id]; + delete segment.reversibility; + delete segment.from_node_coefficient; + delete segment.to_node_coefficient; + delete segment.data; + } + } + for (var n_id in out.nodes) { + var node = out.nodes[n_id]; + delete node.data; + delete node.data_string; + } + + if (this.debug) { + d3.json('map_spec.json', function(error, spec) { + if (error) { + console.warn(error); + return; + } + utils.check_r(out, spec.spec, spec.can_be_none); + }); + } + + return out; + } + function save_svg() { + console.log("Exporting SVG"); + this.callback_manager.run('before_svg_export'); + // turn of zoom and translate so that illustrator likes the map + var window_scale = this.zoom_container.window_scale, + window_translate = this.zoom_container.window_translate, + canvas_size_and_loc = this.canvas.size_and_location(), + mouse_node_size_and_trans = { w: this.canvas.mouse_node.attr('width'), + h: this.canvas.mouse_node.attr('height'), + transform: this.canvas.mouse_node.attr('transform')}; + this.zoom_container.go_to(1.0, {x: -canvas_size_and_loc.x, y: -canvas_size_and_loc.y}, false); + this.svg.attr('width', canvas_size_and_loc.width); + this.svg.attr('height', canvas_size_and_loc.height); + this.canvas.mouse_node.attr('width', '0px'); + this.canvas.mouse_node.attr('height', '0px'); + this.canvas.mouse_node.attr('transform', null); + utils.export_svg("saved_map", this.svg, true); + this.zoom_container.go_to(window_scale, window_translate, false); + this.svg.attr('width', null); + this.svg.attr('height', null); + this.canvas.mouse_node.attr('width', mouse_node_size_and_trans.w); + this.canvas.mouse_node.attr('height', mouse_node_size_and_trans.h); + this.canvas.mouse_node.attr('transform', mouse_node_size_and_trans.transform); + this.callback_manager.run('after_svg_export'); + } +}); + +define('PlacedDiv',['utils', 'Map'], function(utils, Map) { + /** A container to position an html div to match the coordinates of a SVG element. + + */ + + var PlacedDiv = utils.make_class(); + // instance methods + PlacedDiv.prototype = { init: init, + show: show, + hide: hide, + is_visible: is_visible, + place: place }; + return PlacedDiv; + + // definitions + function init(div, map) { + // make the input box + this.div = div; + + if (map instanceof Map) { + this.map = map; + } else { + console.error('Cannot set the map. It is not an instance of builder/Map'); + } + } + + function show() { + this.div.style('display', null); + } + + function hide() { + this.div.style('display', 'none'); + } + + function is_visible() { + return this.div.style('display') != 'none'; + } + + function place(coords) { + /** Position the html div to match the given SVG coordinates. + + */ + // move the new input + var d = {x: 240, y: 0}, + window_translate = this.map.zoom_container.window_translate, + window_scale = this.map.zoom_container.window_scale, + map_size = this.map.get_size(), + left = Math.max(20, + Math.min(map_size.width - 270, + (window_scale * coords.x + window_translate.x - d.x))), + top = Math.max(20, + Math.min(map_size.height - 40, + (window_scale * coords.y + window_translate.y - d.y))); + this.div.style('position', 'absolute') + .style('display', 'block') + .style('left', left+'px') + .style('top', top+'px'); + } +}); + +/** + * complete.ly 1.0.0 + * MIT Licensing + * Copyright (c) 2013 Lorenzo Puccetti + * + * This Software shall be used for doing good things, not bad things. + * +**/ +define('lib/complete.ly',[],function() { +return function(container, config) { + config = config || {}; + config.fontSize = config.fontSize || '16px'; + config.fontFamily = config.fontFamily || 'sans-serif'; + config.promptInnerHTML = config.promptInnerHTML || ''; + config.color = config.color || '#333'; + config.hintColor = config.hintColor || '#aaa'; + config.backgroundColor = config.backgroundColor || '#fff'; + config.dropDownBorderColor = config.dropDownBorderColor || '#aaa'; + config.dropDownZIndex = config.dropDownZIndex || '100'; // to ensure we are in front of everybody + config.dropDownOnHoverBackgroundColor = config.dropDownOnHoverBackgroundColor || '#ddd'; + + var txtInput = document.createElement('input'); + txtInput.type ='text'; + txtInput.spellcheck = false; + txtInput.style.fontSize = config.fontSize; + txtInput.style.fontFamily = config.fontFamily; + txtInput.style.color = config.color; + txtInput.style.backgroundColor = config.backgroundColor; + txtInput.style.width = '100%'; + txtInput.style.outline = '0'; + txtInput.style.border = '0'; + txtInput.style.margin = '0'; + txtInput.style.padding = '0'; + + var txtHint = txtInput.cloneNode(); + txtHint.disabled=''; + txtHint.style.position = 'absolute'; + txtHint.style.top = '0'; + txtHint.style.left = '0'; + txtHint.style.borderColor = 'transparent'; + txtHint.style.boxShadow = 'none'; + txtHint.style.color = config.hintColor; + + txtInput.style.backgroundColor ='transparent'; + txtInput.style.verticalAlign = 'top'; + txtInput.style.position = 'relative'; + + var wrapper = document.createElement('div'); + wrapper.style.position = 'relative'; + wrapper.style.outline = '0'; + wrapper.style.border = '0'; + wrapper.style.margin = '0'; + wrapper.style.padding = '0'; + + var prompt = document.createElement('div'); + prompt.style.position = 'absolute'; + prompt.style.outline = '0'; + prompt.style.margin = '0'; + prompt.style.padding = '0'; + prompt.style.border = '0'; + prompt.style.fontSize = config.fontSize; + prompt.style.fontFamily = config.fontFamily; + prompt.style.color = config.color; + prompt.style.backgroundColor = config.backgroundColor; + prompt.style.top = '0'; + prompt.style.left = '0'; + prompt.style.overflow = 'hidden'; + prompt.innerHTML = config.promptInnerHTML; + prompt.style.background = 'transparent'; + if (document.body === undefined) { + throw 'document.body is undefined. The library was wired up incorrectly.'; } - function highlight_node(node_id) { - this.highlight(this.sel.selectAll('#n'+node_id).selectAll('text')); + document.body.appendChild(prompt); + var w = prompt.getBoundingClientRect().right; // works out the width of the prompt. + wrapper.appendChild(prompt); + prompt.style.visibility = 'visible'; + prompt.style.left = '-'+w+'px'; + wrapper.style.marginLeft= w+'px'; + + wrapper.appendChild(txtHint); + wrapper.appendChild(txtInput); + + var dropDown = document.createElement('div'); + dropDown.style.position = 'absolute'; + dropDown.style.visibility = 'hidden'; + dropDown.style.outline = '0'; + dropDown.style.margin = '0'; + dropDown.style.padding = '0'; + dropDown.style.textAlign = 'left'; + dropDown.style.fontSize = config.fontSize; + dropDown.style.fontFamily = config.fontFamily; + dropDown.style.backgroundColor = config.backgroundColor; + dropDown.style.zIndex = config.dropDownZIndex; + dropDown.style.cursor = 'default'; + dropDown.style.borderStyle = 'solid'; + dropDown.style.borderWidth = '1px'; + dropDown.style.borderColor = config.dropDownBorderColor; + dropDown.style.overflowX= 'hidden'; + dropDown.style.whiteSpace = 'pre'; + dropDown.style.overflowY = 'scroll'; // note: this might be ugly when the scrollbar is not required. however in this way the width of the dropDown takes into account + + + var createDropDownController = function(elem) { + var rows = []; + var ix = 0; + var oldIndex = -1; + + var onMouseOver = function() { this.style.outline = '1px solid #ddd'; } + var onMouseOut = function() { this.style.outline = '0'; } + var onMouseDown = function() { p.hide(); p.onmouseselection(this.__hint); } + + var p = { + hide : function() { elem.style.visibility = 'hidden'; }, + refresh : function(token, array) { + elem.style.visibility = 'hidden'; + ix = 0; + elem.innerHTML =''; + var vph = (window.innerHeight || document.documentElement.clientHeight); + var rect = elem.parentNode.getBoundingClientRect(); + var distanceToTop = rect.top - 6; // heuristic give 6px + var distanceToBottom = vph - rect.bottom -6; // distance from the browser border. + + rows = []; + for (var i=0;i'+array[i].substring(token.length)+''; + rows.push(divRow); + elem.appendChild(divRow); + } + if (rows.length===0) { + return; // nothing to show. + } + if (rows.length===1 && token === rows[0].__hint) { + return; // do not show the dropDown if it has only one element which matches what we have just displayed. + } + + if (rows.length<2) return; + p.highlight(0); + + if (distanceToTop > distanceToBottom*3) { // Heuristic (only when the distance to the to top is 4 times more than distance to the bottom + elem.style.maxHeight = distanceToTop+'px'; // we display the dropDown on the top of the input text + elem.style.top =''; + elem.style.bottom ='100%'; + } else { + elem.style.top = '100%'; + elem.style.bottom = ''; + elem.style.maxHeight = distanceToBottom+'px'; + } + elem.style.visibility = 'visible'; + }, + highlight : function(index) { + if (oldIndex !=-1 && rows[oldIndex]) { + rows[oldIndex].style.backgroundColor = config.backgroundColor; + } + rows[index].style.backgroundColor = config.dropDownOnHoverBackgroundColor; // <-- should be config + oldIndex = index; + }, + move : function(step) { // moves the selection either up or down (unless it's not possible) step is either +1 or -1. + if (elem.style.visibility === 'hidden') return ''; // nothing to move if there is no dropDown. (this happens if the user hits escape and then down or up) + if (ix+step === -1 || ix+step === rows.length) return rows[ix].__hint; // NO CIRCULAR SCROLLING. + ix+=step; + p.highlight(ix); + return rows[ix].__hint;//txtShadow.value = uRows[uIndex].__hint ; + }, + onmouseselection : function() {} // it will be overwritten. + }; + return p; } - function highlight(sel) { - this.sel.selectAll('.highlight') - .classed('highlight', false); - if (sel!==null) { - sel.classed('highlight', true); - } + + var dropDownController = createDropDownController(dropDown); + + dropDownController.onmouseselection = function(text) { + txtInput.value = txtHint.value = leftSide+text; + rs.onChange(txtInput.value); // <-- forcing it. + registerOnTextChangeOldValue = txtInput.value; // <-- ensure that mouse down will not show the dropDown now. + setTimeout(function() { txtInput.focus(); },0); // <-- I need to do this for IE } - - // ------------------------------------------------------------------------- - // IO - - function save() { - console.log("Saving"); - utils.download_json(this.map_for_export(), "saved_map"); + + wrapper.appendChild(dropDown); + container.appendChild(wrapper); + + var spacer; + var leftSide; // <-- it will contain the leftSide part of the textfield (the bit that was already autocompleted) + + + function calculateWidthForText(text) { + if (spacer === undefined) { // on first call only. + spacer = document.createElement('span'); + spacer.style.visibility = 'hidden'; + spacer.style.position = 'fixed'; + spacer.style.outline = '0'; + spacer.style.margin = '0'; + spacer.style.padding = '0'; + spacer.style.border = '0'; + spacer.style.left = '0'; + spacer.style.whiteSpace = 'pre'; + spacer.style.fontSize = config.fontSize; + spacer.style.fontFamily = config.fontFamily; + spacer.style.fontWeight = 'normal'; + document.body.appendChild(spacer); + } + + // Used to encode an HTML string into a plain text. + // taken from http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding + spacer.innerHTML = String(text).replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(//g, '>'); + return spacer.getBoundingClientRect().right; } - function map_for_export() { - var out = { reactions: utils.clone(this.reactions), - nodes: utils.clone(this.nodes), - membranes: utils.clone(this.membranes), - text_labels: utils.clone(this.text_labels), - canvas: this.canvas.size_and_location() }; - - // remove extra data - for (var r_id in out.reactions) { - var reaction = out.reactions[r_id]; - delete reaction.data; - delete reaction.data_string; - for (var s_id in reaction.segments) { - var segment = reaction.segments[s_id]; - delete segment.reversibility; - delete segment.from_node_coefficient; - delete segment.to_node_coefficient; - delete segment.data; - } - } - for (var n_id in out.nodes) { - var node = out.nodes[n_id]; - delete node.data; - delete node.data_string; - } + + + var rs = { + onArrowDown : function() {}, // defaults to no action. + onArrowUp : function() {}, // defaults to no action. + onEnter : function() {}, // defaults to no action. + onTab : function() {}, // defaults to no action. + onChange: function() { rs.repaint() }, // defaults to repainting. + startFrom: 0, + options: [], + wrapper : wrapper, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) + input : txtInput, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) + hint : txtHint, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) + dropDown : dropDown, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) + prompt : prompt, + setText : function(text) { + txtHint.value = text; + txtInput.value = text; + }, + getText : function() { + return txtInput.value; + }, + hideDropDown : function() { + dropDownController.hide(); + }, + repaint : function() { + var text = txtInput.value; + var startFrom = rs.startFrom; + var options = rs.options; + var optionsLength = options.length; + + // breaking text in leftSide and token. + var token = text.substring(startFrom); + leftSide = text.substring(0,startFrom); + + // updating the hint. + txtHint.value =''; + for (var i=0;i 0) { // if there is a hint + dropDownController.hide(); + txtInput.value = txtHint.value; + var hasTextChanged = registerOnTextChangeOldValue != txtInput.value + registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. + // for example imagine the array contains the following words: bee, beef, beetroot + // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) + if (hasTextChanged) { + rs.onChange(txtInput.value); // <-- forcing it. + } + } + return; + } + + if (keyCode == 13) { // enter (autocomplete triggered) + if (txtHint.value.length == 0) { // if there is a hint + rs.onEnter(); + } else { + var wasDropDownHidden = (dropDown.style.visibility == 'hidden'); + dropDownController.hide(); + + if (wasDropDownHidden) { + txtHint.value = txtInput.value; // ensure that no hint is left. + txtInput.focus(); + rs.onEnter(); + return; + } + + txtInput.value = txtHint.value; + var hasTextChanged = registerOnTextChangeOldValue != txtInput.value + registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. + // for example imagine the array contains the following words: bee, beef, beetroot + // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) + if (hasTextChanged) { + rs.onChange(txtInput.value); // <-- forcing it. + } + + } + return; + } + + if (keyCode == 40) { // down + var m = dropDownController.move(+1); + if (m == '') { rs.onArrowDown(); } + txtHint.value = leftSide+m; + return; + } + + if (keyCode == 38 ) { // up + var m = dropDownController.move(-1); + if (m == '') { rs.onArrowUp(); } + txtHint.value = leftSide+m; + e.preventDefault(); + e.stopPropagation(); + return; + } + + // it's important to reset the txtHint on key down. + // think: user presses a letter (e.g. 'x') and never releases... you get (xxxxxxxxxxxxxxxxx) + // and you would see still the hint + txtHint.value =''; // resets the txtHint. (it might be updated onKeyUp) + + }; + + if (txtInput.addEventListener) { + txtInput.addEventListener("keydown", keyDownHandler, false); + } else { // is this a fair assumption: that attachEvent will exist ? + txtInput.attachEvent('onkeydown', keyDownHandler); // IE<9 } + return rs; +} }); define('ZoomContainer',["utils", "CallbackManager"], function(utils, CallbackManager) { @@ -9298,45 +9393,45 @@ define('DirectionArrow',["utils"], function(utils) { } }); -define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackManager", "draw", "DirectionArrow"], function(utils, completely, Map, ZoomContainer, CallbackManager, draw, DirectionArrow) { +define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'CallbackManager', 'draw', 'DirectionArrow'], function(utils, PlacedDiv, completely, Map, ZoomContainer, CallbackManager, draw, DirectionArrow) { /** */ - var Input = utils.make_class(); + var BuildInput = utils.make_class(); // instance methods - Input.prototype = { init: init, - setup_map_callbacks: setup_map_callbacks, - setup_zoom_callbacks: setup_zoom_callbacks, - is_visible: is_visible, - toggle: toggle, - show_dropdown: show_dropdown, - hide_dropdown: hide_dropdown, - place_at_selected: place_at_selected, - place: place, - reload_at_selected: reload_at_selected, - reload: reload, - toggle_start_reaction_listener: toggle_start_reaction_listener, - hide_target: hide_target, - show_target: show_target }; - - return Input; + BuildInput.prototype = { init: init, + setup_map_callbacks: setup_map_callbacks, + setup_zoom_callbacks: setup_zoom_callbacks, + is_visible: is_visible, + toggle: toggle, + show_dropdown: show_dropdown, + hide_dropdown: hide_dropdown, + place_at_selected: place_at_selected, + place: place, + reload_at_selected: reload_at_selected, + reload: reload, + toggle_start_reaction_listener: toggle_start_reaction_listener, + hide_target: hide_target, + show_target: show_target }; + + return BuildInput; // definitions function init(selection, map, zoom_container) { // set up container - var new_sel = selection.append("div").attr("id", "rxn-input"); + var new_sel = selection.append('div').attr('id', 'rxn-input'); + this.placed_div = PlacedDiv(new_sel); // set up complete.ly - var c = completely(new_sel.node(), { backgroundColor: "#eee" }); + var c = completely(new_sel.node(), { backgroundColor: '#eee' }); d3.select(c.input) // .attr('placeholder', 'Reaction ID -- Flux') .on('input', function() { this.value = this.value - // .replace("/","") + // .replace("/","") .replace(" ","") .replace("\\","") .replace("<",""); }); - this.selection = new_sel; this.completely = c; // close button new_sel.append('button').attr('class', "button input-close-button") @@ -9397,9 +9492,11 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa } }.bind(this)); } + function is_visible() { - return this.selection.style('display') != 'none'; + return this.placed_div.is_visible(); } + function toggle(on_off) { if (on_off===undefined) this.is_active = !this.is_active; else this.is_active = on_off; @@ -9414,7 +9511,7 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa .add_escape_listener(function() { this.hide_dropdown(); }.bind(this)); } else { this.toggle_start_reaction_listener(false); - this.selection.style("display", "none"); + this.placed_div.hide(); this.completely.input.blur(); this.completely.hideDropDown(); this.map.set_status(null); @@ -9425,14 +9522,14 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa } } function show_dropdown(coords) { - this.selection.style("display", "block"); + this.placed_selection.show(); this.completely.input.blur(); this.completely.repaint(); this.completely.setText(""); this.completely.input.focus(); } function hide_dropdown() { - this.selection.style("display", "none"); + this.placed_selection.hide(); this.completely.hideDropDown(); } function place_at_selected() { @@ -9448,20 +9545,21 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa this.place(coords); } function place(coords) { - var d = {x: 240, y: 0}, - window_translate = this.map.zoom_container.window_translate, - window_scale = this.map.zoom_container.window_scale, - map_size = this.map.get_size(); - var left = Math.max(20, - Math.min(map_size.width - 270, - (window_scale * coords.x + window_translate.x - d.x))); - var top = Math.max(20, - Math.min(map_size.height - 40, - (window_scale * coords.y + window_translate.y - d.y))); - this.selection.style('position', 'absolute') - .style('display', 'block') - .style('left',left+'px') - .style('top',top+'px'); + this.placed_selection.place(coords); + // var d = {x: 240, y: 0}, + // window_translate = this.map.zoom_container.window_translate, + // window_scale = this.map.zoom_container.window_scale, + // map_size = this.map.get_size(); + // var left = Math.max(20, + // Math.min(map_size.width - 270, + // (window_scale * coords.x + window_translate.x - d.x))); + // var top = Math.max(20, + // Math.min(map_size.height - 40, + // (window_scale * coords.y + window_translate.y - d.y))); + // this.selection.style('position', 'absolute') + // .style('display', 'block') + // .style('left',left+'px') + // .style('top',top+'px'); this.direction_arrow.set_location(coords); this.direction_arrow.show(); @@ -9578,12 +9676,12 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa if (x.string.toLowerCase()==text.toLowerCase()) { if (starting_from_scratch) { map.new_reaction_from_scratch(x.reaction_abbreviation, - coords, - direction_arrow.get_rotation()); + coords, + direction_arrow.get_rotation()); } else { map.new_reaction_for_metabolite(x.reaction_abbreviation, - selected_node.node_id, - direction_arrow.get_rotation()); + selected_node.node_id, + direction_arrow.get_rotation()); } } }); @@ -9612,26 +9710,26 @@ define('Input',["utils", "lib/complete.ly", "Map", "ZoomContainer", "CallbackMa this.start_reaction_listener = on_off; if (this.start_reaction_listener) {; - this.map.sel.on('click.start_reaction', function(node) { - // TODO fix this hack - if (this.direction_arrow.dragging) return; - // reload the reaction input - var coords = { x: d3.mouse(node)[0], - y: d3.mouse(node)[1] }; - // unselect metabolites - this.map.deselect_nodes(); - this.map.deselect_text_labels(); - // reload the reaction input - this.reload(null, coords, true); - // generate the target symbol - this.show_target(this.map, coords); - }.bind(this, this.map.sel.node())); - this.map.sel.classed('start-reaction-cursor', true); - } else { - this.map.sel.on('click.start_reaction', null); - this.map.sel.classed('start-reaction-cursor', false); - this.hide_target(); - } + this.map.sel.on('click.start_reaction', function(node) { + // TODO fix this hack + if (this.direction_arrow.dragging) return; + // reload the reaction input + var coords = { x: d3.mouse(node)[0], + y: d3.mouse(node)[1] }; + // unselect metabolites + this.map.deselect_nodes(); + this.map.deselect_text_labels(); + // reload the reaction input + this.reload(null, coords, true); + // generate the target symbol + this.show_target(this.map, coords); + }.bind(this, this.map.sel.node())); + this.map.sel.classed('start-reaction-cursor', true); + } else { + this.map.sel.on('click.start_reaction', null); + this.map.sel.classed('start-reaction-cursor', false); + this.hide_target(); + } } function hide_target() { @@ -9685,17 +9783,8 @@ define('CobraModel',["utils", "data_styles"], function(utils, data_styles) { delete this.metabolites[the_id].id; } - // get cofactors if preset - if ('cofactors' in model_data) { - if (model_data.cofactors instanceof Array) { - this.cofactors = model_data.cofactors; - } else { - console.warn('model_data.cofactors should be an array. Ignoring it'); - this.cofactors = []; - } - } else { - this.cofactors = []; - } + this.cofactors = ['atp', 'adp', 'nad', 'nadh', 'nadp', 'nadph', 'gtp', + 'gdp', 'h']; } function apply_reaction_data(reaction_data, styles) { @@ -10644,7 +10733,31 @@ define('SettingsBar',["utils", "CallbackManager", "lib/bacon"], function(utils, } }); -define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush", "CallbackManager", "ui", "SearchBar", "Settings", "SettingsBar"], function(utils, Input, ZoomContainer, Map, CobraModel, Brush, CallbackManager, ui, SearchBar, Settings, SettingsBar) { +define('TextEditInput',['utils', 'PlacedDiv'], function(utils, PlacedDiv) { + /** + */ + + var TextEditInput = utils.make_class(); + // instance methods + TextEditInput.prototype = { init: init, + is_visible: is_visible }; + + return TextEditInput; + + // definitions + function init(selection, map, zoom_container) { + var div = selection.append('div') + .attr('id', 'text-edit-input'); + this.placed_div = PlacedDiv(div); + div.append('input').style('display', 'none'); + } + + function is_visible() { + return this.placed_div.is_visible(); + } +}); + +define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'CallbackManager', 'ui', 'SearchBar', 'Settings', 'SettingsBar', 'TextEditInput'], function(utils, BuildInput, ZoomContainer, Map, CobraModel, Brush, CallbackManager, ui, SearchBar, Settings, SettingsBar, TextEditInput) { /** A Builder object contains all the ui and logic to generate a map builder or viewer. Builder(options) @@ -10661,6 +10774,7 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush brush_mode: brush_mode, zoom_mode: zoom_mode, rotate_mode: rotate_mode, + text_mode: text_mode, _toggle_direction_buttons: _toggle_direction_buttons, _setup_menu: _setup_menu, _setup_simple_zoom_buttons: _setup_simple_zoom_buttons, @@ -10826,8 +10940,12 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush } // set up the reaction input with complete.ly - this.reaction_input = Input(this.options.selection, this.map, - this.zoom_container); + this.reaction_input = BuildInput(this.options.selection, this.map, + this.zoom_container); + + // set up the text edit input + this.text_edit_input = TextEditInput(this.options.selection, this.map, + this.zoom_container); // set up the Brush this.brush = new Brush(zoomed_sel, false, this.map, '.canvas-group'); @@ -10864,7 +10982,7 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush this.map.key_manager.assigned_keys = keys; // tell the key manager about the reaction input and search bar this.map.key_manager.input_list = [this.reaction_input, this.search_bar, - this.settings_page]; + this.settings_page, this.text_edit_input]; // make sure the key manager remembers all those changes this.map.key_manager.update(); // turn it on/off @@ -10923,7 +11041,9 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush this.map.behavior.toggle_selectable_click(mode=='build' || mode=='brush' || mode=='rotate'); this.map.behavior.toggle_selectable_drag(mode=='brush' || mode=='rotate'); this.map.behavior.toggle_label_drag(mode=='brush'); - if (mode=='view') + this.map.behavior.toggle_text_label_edit(mode=='text'); + // edit selections + if (mode=='view' || mode=='text') this.map.select_none(); if (mode=='rotate') this.map.deselect_text_labels(); @@ -10948,6 +11068,10 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush function rotate_mode() { this.callback_manager.run('rotate_mode'); this.set_mode('rotate'); + } + function text_mode() { + this.callback_manager.run('text_mode'); + this.set_mode('text'); } function _setup_menu(menu_selection, button_selection, map, zoom_container, key_manager, keys, enable_editing) { @@ -11005,6 +11129,9 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush .button({ key: keys.rotate_mode, id: 'rotate-mode-menu-button', text: "Rotate mode (r)" }) + .button({ key: keys.text_mode, + id: 'text-mode-menu-button', + text: "Text mode (t)" }) .divider() .button({ key: keys.delete, // icon: "glyphicon glyphicon-trash", @@ -11092,7 +11219,11 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush .button({ key: keys.rotate_mode, id: 'rotate-mode-button', icon: "glyphicon glyphicon-repeat", - tooltip: "Rotate mode (r)" }); + tooltip: "Rotate mode (r)" }) + .button({ key: keys.text_mode, + id: 'text-mode-button', + icon: "glyphicon glyphicon-font", + tooltip: "Text mode (r)" }); // arrow buttons this.direction_buttons = button_panel.append('li'); @@ -11117,7 +11248,8 @@ define('Builder',["utils", "Input", "ZoomContainer", "Map", "CobraModel", "Brush '#zoom-mode-menu-button', '#brush-mode-menu-button', '#rotate-mode-menu-button', - '#view-mode-menu-button']; + '#view-mode-menu-button', + '#text-mode-menu-button']; for (var i=0, l=ids.length; i0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label").style("cursor","default")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label").style("cursor","default")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("text").attr("class","text-label label").style("cursor","default").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function f(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function l(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("text-label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("text-label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="text-label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="text-label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function c(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function h(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function v(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_selectable_drag:a,toggle_label_drag:f,get_selectable_drag:l,get_bezier_drag:c,get_reaction_label_drag:h,get_node_label_drag:p,get_generic_drag:d,get_generic_angular_drag:v},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.selectable_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t)}function Z(t,n){var r=this.segments_and_reactions_for_nodes(t),i=r.reactions,s=r.segment_objs_w_segments,o=e.clone(t),u=e.clone(s),a=e.clone(i),f=e.clone(n),l=function(e,n,r,i){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(i)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);l(t,i,s,n),this.undo_stack.push(function(){this.extend_nodes(o),this.extend_reactions(a);var r=Object.keys(a);u.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in o)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),r.indexOf(e.reaction_id)==-1&&r.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var l=this.update_reaction_data_domain();l?this.draw_all_reactions():this.draw_these_reactions(r)}else this.draw_these_reactions(r);if(this.has_metabolite_data()){var l=this.update_metabolite_data_domain();l?this.draw_all_nodes():this.draw_these_nodes(Object.keys(o))}else this.draw_these_nodes(Object.keys(o));e.extend(this.text_labels,f),this.draw_these_text_labels(Object.keys(f)),n=e.clone(f),t=e.clone(o),s=e.clone(u),i=e.clone(a)}.bind(this),function(){l(t,i,s,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ct(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function ht(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function pt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function dt(e){this._zoom_extent(e,"nodes")}function vt(e){this._zoom_extent(e,"canvas")}function mt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function gt(){return this.zoom_container.get_size()}function yt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function Et(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function St(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function xt(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function Tt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Nt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:lt,cycle_primary_node:ct,make_selected_node_primary:ht,extend_nodes:at,extend_reactions:ft,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:pt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:dt,zoom_extent_canvas:vt,_zoom_extent:mt,get_size:gt,zoom_to_reaction:yt,zoom_to_node:bt,highlight_reaction:wt,highlight_node:Et,highlight:St,save:xt,map_for_export:Tt,save_svg:Nt},h}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("Input",["utils","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o){function a(e,s,u){var a=e.append("div").attr("id","rxn-input"),f=t(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.selection=a,this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(s instanceof n){this.map=s;var l=90;this.direction_arrow=new o(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s)}else console.error("Cannot set the map. It is not an instance of builder/Map");u instanceof r?(this.zoom_container=u,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new i,this.toggle(!1),this.target_coords=null}function f(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function l(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function c(){return this.selection.style("display")!="none"}function h(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.selection.style("display","none"),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function p(e){this.selection.style("display","block"),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function d(){this.selection.style("display","none"),this.completely.hideDropDown()}function v(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function m(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.selection.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px"),this.direction_arrow.set_location(e),this.direction_arrow.show()}function g(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function y(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("class","text-label").append("text").attr("class","label").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0)}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("text-label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("text-label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="text-label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="text-label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function m(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,get_selectable_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_generic_drag:v,get_generic_angular_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t)}function Z(t,n){var r=this.segments_and_reactions_for_nodes(t),i=r.reactions,s=r.segment_objs_w_segments,o=e.clone(t),u=e.clone(s),a=e.clone(i),f=e.clone(n),l=function(e,n,r,i){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(i)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);l(t,i,s,n),this.undo_stack.push(function(){this.extend_nodes(o),this.extend_reactions(a);var r=Object.keys(a);u.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in o)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),r.indexOf(e.reaction_id)==-1&&r.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var l=this.update_reaction_data_domain();l?this.draw_all_reactions():this.draw_these_reactions(r)}else this.draw_these_reactions(r);if(this.has_metabolite_data()){var l=this.update_metabolite_data_domain();l?this.draw_all_nodes():this.draw_these_nodes(Object.keys(o))}else this.draw_these_nodes(Object.keys(o));e.extend(this.text_labels,f),this.draw_these_text_labels(Object.keys(f)),n=e.clone(f),t=e.clone(o),s=e.clone(u),i=e.clone(a)}.bind(this),function(){l(t,i,s,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ct(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function ht(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function pt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function dt(e){this._zoom_extent(e,"nodes")}function vt(e){this._zoom_extent(e,"canvas")}function mt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function gt(){return this.zoom_container.get_size()}function yt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function Et(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function St(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function xt(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function Tt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Nt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:lt,cycle_primary_node:ct,make_selected_node_primary:ht,extend_nodes:at,extend_reactions:ft,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:pt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:dt,zoom_extent_canvas:vt,_zoom_extent:mt,get_size:gt,zoom_to_reaction:yt,zoom_to_node:bt,highlight_reaction:wt,highlight_node:Et,highlight:St,save:xt,map_for_export:Tt,save_svg:Nt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n){this.div=e,n instanceof t?this.map=n:console.error("Cannot set the map. It is not an instance of builder/Map")}function i(){this.div.style("display",null)}function s(){this.div.style("display","none")}function o(){return this.div.style("display")!="none"}function u(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.div.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px")}var n=e.make_class();return n.prototype={init:r,show:i,hide:s,is_visible:o,place:u},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,o,a){var f=e.append("div").attr("id","rxn-input");this.placed_div=t(f);var l=n(f.node(),{backgroundColor:"#eee"});d3.select(l.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=l,f.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(o instanceof r){this.map=o;var c=90;this.direction_arrow=new u(o.sel),this.direction_arrow.set_rotation(c),this.setup_map_callbacks(o)}else console.error("Cannot set the map. It is not an instance of builder/Map");a instanceof i?(this.zoom_container=a,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new s,this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_selection.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_selection.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_selection.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Mon, 11 Aug 2014 11:59:32 -0700 Subject: [PATCH 06/33] Don't clear cache during testing --- escher/tests/test_plots.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/escher/tests/test_plots.py b/escher/tests/test_plots.py index 392345e1..6172c52e 100644 --- a/escher/tests/test_plots.py +++ b/escher/tests/test_plots.py @@ -15,22 +15,22 @@ def test_get_cache_dir(): d = get_cache_dir(name='maps') assert os.path.isdir(d) -def test_clear_cache(): - clear_cache() - d = get_cache_dir(name='maps') - assert len(os.listdir(d)) == 0 - d = get_cache_dir(name='models') - assert len(os.listdir(d)) == 0 +# def test_clear_cache(): +# clear_cache() +# d = get_cache_dir(name='maps') +# assert len(os.listdir(d)) == 0 +# d = get_cache_dir(name='models') +# assert len(os.listdir(d)) == 0 -def test_list_cached_maps(): - clear_cache() - Builder(map_name='iJO1366_central_metabolism') - assert list_cached_maps() == ['iJO1366_central_metabolism'] +# def test_list_cached_maps(): +# clear_cache() +# Builder(map_name='iJO1366_central_metabolism') +# assert list_cached_maps() == ['iJO1366_central_metabolism'] -def test_list_cached_models(): - clear_cache() - Builder(model_name='iJO1366') - assert list_cached_models() == ['iJO1366'] +# def test_list_cached_models(): +# clear_cache() +# Builder(model_name='iJO1366') +# assert list_cached_models() == ['iJO1366'] def test_load_resource(tmpdir): assert load_resource('{"r": "val"}', 'name') == '{"r": "val"}' From e21f5d8edbb68f3a6e21b9f2dc9dba78ffb7948b Mon Sep 17 00:00:00 2001 From: Zachary King Date: Wed, 20 Aug 2014 16:41:48 -0400 Subject: [PATCH 07/33] Add, edit, delete, and undo/redo text labels. --- escher/css/builder-embed.css | 2 +- escher/css/builder.css | 6 + escher/js/src/Behavior.js | 20 ++- escher/js/src/BuildInput.js | 24 +-- escher/js/src/Map.js | 55 ++++-- escher/js/src/PlacedDiv.js | 35 ++-- escher/js/src/TextEditInput.js | 138 ++++++++++++++- escher/js/src/ZoomContainer.js | 2 + escher/js/src/build.js | 11 +- escher/js/src/draw.js | 5 +- escher/lib/escher.1.0.0b3.js | 290 +++++++++++++++++++++++++------ escher/lib/escher.1.0.0b3.min.js | 2 +- 12 files changed, 482 insertions(+), 108 deletions(-) diff --git a/escher/css/builder-embed.css b/escher/css/builder-embed.css index 862f6534..788219d3 100644 --- a/escher/css/builder-embed.css +++ b/escher/css/builder-embed.css @@ -40,7 +40,7 @@ stroke-width: 3px; stroke: rgb(20, 113, 199); } -.selected.text-label { +.selected .label { fill: rgb(20, 113, 199); } .metabolite-circle { diff --git a/escher/css/builder.css b/escher/css/builder.css index 567cecd0..073d1d81 100644 --- a/escher/css/builder.css +++ b/escher/css/builder.css @@ -190,4 +190,10 @@ .input-close-button:hover { color: #ff3333; font-weight: bold; +} +/* text edit input */ +#text-edit-input input { + width: 500px; + border: none; + font-size: 22px; } \ No newline at end of file diff --git a/escher/js/src/Behavior.js b/escher/js/src/Behavior.js index daca716e..551bf2a0 100644 --- a/escher/js/src/Behavior.js +++ b/escher/js/src/Behavior.js @@ -100,7 +100,7 @@ define(["utils", "build"], function(utils, build) { var selected_nodes = this.map.get_selected_nodes(); if (Object.keys(selected_nodes).length == 0) { - console.log('No selected nodes'); + console.warn('No selected nodes'); return; } @@ -263,17 +263,25 @@ define(["utils", "build"], function(utils, build) { // run the callback var coords_a = d3.transform(d3.select(this).attr('transform')).translate, coords = {x: coords_a[0], y: coords_a[1]}; - map.callback_manager.run('edit_text_label', coords); + map.callback_manager.run('edit_text_label', d3.select(this), coords); d3.event.stopPropagation(); }; this.map.sel.select('#text-labels') .selectAll('.label') .classed('edit-text-cursor', true); + // add the new-label listener + this.map.sel.on('click.new_text_label', function(node) { + var coords = { x: d3.mouse(node)[0], + y: d3.mouse(node)[1] }; + this.map.callback_manager.run('new_text_label', coords); + }.bind(this, this.map.sel.node())); } else { this.text_label_click = this.selectable_click; this.map.sel.select('#text-labels') .selectAll('.label') .classed('edit-text-cursor', false); + // remove the new-label listener + this.map.sel.on('click.new_text_label', null); } } @@ -336,7 +344,7 @@ define(["utils", "build"], function(utils, build) { total_displacement = {x: 0, y: 0}; // If a text label is selected, the rest is not necessary - if (d3.select(this).attr('class').indexOf('text-label')==-1) { + if (d3.select(this).attr('class').indexOf('label')==-1) { // Note that dragstart is called even for a click event var data = this.parentNode.__data__, bigg_id = data.bigg_id, @@ -366,13 +374,13 @@ define(["utils", "build"], function(utils, build) { behavior.on("drag", function() { // get the grabbed id var grabbed = {}; - if (d3.select(this).attr('class').indexOf('text-label')==-1) { + if (d3.select(this).attr('class').indexOf('label')==-1) { // if it is a node grabbed['type'] = 'node'; grabbed['id'] = this.parentNode.__data__.node_id; } else { // if it is a text label - grabbed['type'] = 'text-label'; + grabbed['type'] = 'label'; grabbed['id'] = this.__data__.text_label_id; } @@ -383,7 +391,7 @@ define(["utils", "build"], function(utils, build) { if (grabbed['type']=='node' && selected_node_ids.indexOf(grabbed['id'])==-1) { node_ids_to_drag.push(grabbed['id']); - } else if (grabbed['type']=='text-label' && + } else if (grabbed['type']=='label' && selected_text_label_ids.indexOf(grabbed['id'])==-1) { text_label_ids_to_drag.push(grabbed['id']); } else { diff --git a/escher/js/src/BuildInput.js b/escher/js/src/BuildInput.js index fb66eb12..ddcd0551 100644 --- a/escher/js/src/BuildInput.js +++ b/escher/js/src/BuildInput.js @@ -25,7 +25,8 @@ define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'Callba function init(selection, map, zoom_container) { // set up container var new_sel = selection.append('div').attr('id', 'rxn-input'); - this.placed_div = PlacedDiv(new_sel); + this.placed_div = PlacedDiv(new_sel, map, {x: 240, y: 0}); + this.placed_div.hide(); // set up complete.ly var c = completely(new_sel.node(), { backgroundColor: '#eee' }); d3.select(c.input) @@ -40,7 +41,8 @@ define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'Callba this.completely = c; // close button new_sel.append('button').attr('class', "button input-close-button") - .text("×").on('click', function() { this.hide_dropdown(); }.bind(this)); + .text("×") + .on('click', function() { this.hide_dropdown(); }.bind(this)); if (map instanceof Map) { this.map = map; @@ -52,23 +54,22 @@ define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'Callba this.setup_map_callbacks(map); } else { - console.error('Cannot set the map. It is not an instance of builder/Map'); + throw new Error('Cannot set the map. It is not an instance of ' + + 'Map'); } if (zoom_container instanceof ZoomContainer) { this.zoom_container = zoom_container; - this.setup_zoom_callbacks(); + this.setup_zoom_callbacks(zoom_container); } else { - console.error('Cannot set the zoom_container. It is not an instance of ' + - 'builder/ZoomContainer'); + throw new Error('Cannot set the zoom_container. It is not an ' + + 'instance of ZoomContainer'); } - // set up reaction input callbacks - this.callback_manager = new CallbackManager(); - // toggle off this.toggle(false); this.target_coords = null; } + function setup_map_callbacks(map) { // input map.callback_manager.set('select_metabolite_with_id.input', function(selected_node, coords) { @@ -90,8 +91,9 @@ define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'Callba this.hide_target(); }.bind(this)); } - function setup_zoom_callbacks() { - this.zoom_container.callback_manager.set('zoom.input', function() { + + function setup_zoom_callbacks(zoom_container) { + zoom_container.callback_manager.set('zoom.input', function() { if (this.is_active) { this.place_at_selected(); } diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index 2a68ab47..5ef58ad7 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -64,6 +64,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan make_selected_node_primary: make_selected_node_primary, extend_nodes: extend_nodes, extend_reactions: extend_reactions, + edit_text_label: edit_text_label, // delete delete_selected: delete_selected, delete_selectable: delete_selectable, @@ -643,6 +644,9 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan sel.exit(); } function draw_these_text_labels(text_label_ids) { + /** Draw labels with the given ids. + + */ var text_labels = this.text_labels, text_label_click = this.behavior.text_label_click, text_label_drag = this.behavior.selectable_drag; @@ -999,12 +1003,19 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan selected_text_labels = this.get_selected_text_labels(); if (Object.keys(selected_nodes).length >= 1 || Object.keys(selected_text_labels).length >= 1) - this.delete_selectable(selected_nodes, selected_text_labels); + this.delete_selectable(selected_nodes, selected_text_labels, true); } - function delete_selectable(selected_nodes, selected_text_labels) { - /** Delete the nodes and associated segments and reactions. + function delete_selectable(selected_nodes, selected_text_labels, should_draw) { + /** Delete the nodes and associated segments and reactions. Undoable. - Undoable. + Arguments + --------- + + selected_nodes: An object that is a subset of map.nodes. + + selected_text_labels: An object that is a subset of map.text_labels. + + should_draw: A boolean argument to determine whether to draw the changes to the map. */ var out = this.segments_and_reactions_for_nodes(selected_nodes), @@ -1032,7 +1043,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // redraw // TODO just redraw these nodes, segments, and labels - this.draw_everything(); + if (should_draw) this.draw_everything(); }.bind(this); // delete @@ -1071,19 +1082,21 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan if (scale_changed) this.draw_all_reactions(); else this.draw_these_reactions(reaction_ids_to_draw); } else { - this.draw_these_reactions(reaction_ids_to_draw); + if (should_draw) this.draw_these_reactions(reaction_ids_to_draw); } if (this.has_metabolite_data()) { var scale_changed = this.update_metabolite_data_domain(); - if (scale_changed) this.draw_all_nodes(); - else this.draw_these_nodes(Object.keys(saved_nodes)); + if (should_draw) { + if (scale_changed) this.draw_all_nodes(); + else this.draw_these_nodes(Object.keys(saved_nodes)); + } } else { - this.draw_these_nodes(Object.keys(saved_nodes)); + if (should_draw) this.draw_these_nodes(Object.keys(saved_nodes)); } // redraw the saved text_labels utils.extend(this.text_labels, saved_text_labels); - this.draw_these_text_labels(Object.keys(saved_text_labels)); + if (should_draw) this.draw_these_text_labels(Object.keys(saved_text_labels)); // copy text_labels to re-delete selected_text_labels = utils.clone(saved_text_labels); @@ -1287,6 +1300,26 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan utils.extend(this.reactions, new_reactions); } + function edit_text_label(text_label_id, new_value, should_draw) { + // save old value + var saved_value = this.text_labels[text_label_id].text, + edit_and_draw = function(new_val, should_draw) { + // set the new value + this.text_labels[text_label_id].text = new_val; + if (should_draw) this.draw_these_text_labels([text_label_id]); + }.bind(this); + + // edit the label + edit_and_draw(new_value, should_draw); + + // add to undo stack + this.undo_stack.push(function() { + edit_and_draw(saved_value, should_draw); + }, function () { + edit_and_draw(new_value, should_draw); + }); + } + function new_reaction_for_metabolite(reaction_bigg_id, selected_node_id, direction) { /** Build a new reaction starting with selected_met. @@ -1669,7 +1702,6 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // IO function save() { - console.log("Saving"); utils.download_json(this.map_for_export(), "saved_map"); } function map_for_export() { @@ -1711,7 +1743,6 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan return out; } function save_svg() { - console.log("Exporting SVG"); this.callback_manager.run('before_svg_export'); // turn of zoom and translate so that illustrator likes the map var window_scale = this.zoom_container.window_scale, diff --git a/escher/js/src/PlacedDiv.js b/escher/js/src/PlacedDiv.js index 24d134f1..84aabedb 100644 --- a/escher/js/src/PlacedDiv.js +++ b/escher/js/src/PlacedDiv.js @@ -6,32 +6,27 @@ define(['utils', 'Map'], function(utils, Map) { var PlacedDiv = utils.make_class(); // instance methods PlacedDiv.prototype = { init: init, - show: show, - hide: hide, is_visible: is_visible, - place: place }; + place: place, + hide: hide }; return PlacedDiv; // definitions - function init(div, map) { + function init(div, map, displacement) { // make the input box this.div = div; + if (displacement===undefined) + displacement = {x: 0, y: 0}; + this.displacement = displacement; + if (map instanceof Map) { this.map = map; } else { - console.error('Cannot set the map. It is not an instance of builder/Map'); + throw new Error('Cannot set the map. It is not an instance of Map'); } } - function show() { - this.div.style('display', null); - } - - function hide() { - this.div.style('display', 'none'); - } - function is_visible() { return this.div.style('display') != 'none'; } @@ -40,20 +35,26 @@ define(['utils', 'Map'], function(utils, Map) { /** Position the html div to match the given SVG coordinates. */ + // show the input + this.div.style('display', null); + // move the new input - var d = {x: 240, y: 0}, - window_translate = this.map.zoom_container.window_translate, + var window_translate = this.map.zoom_container.window_translate, window_scale = this.map.zoom_container.window_scale, map_size = this.map.get_size(), left = Math.max(20, Math.min(map_size.width - 270, - (window_scale * coords.x + window_translate.x - d.x))), + (window_scale * coords.x + window_translate.x - this.displacement.x))), top = Math.max(20, Math.min(map_size.height - 40, - (window_scale * coords.y + window_translate.y - d.y))); + (window_scale * coords.y + window_translate.y - this.displacement.y))); this.div.style('position', 'absolute') .style('display', 'block') .style('left', left+'px') .style('top', top+'px'); } + + function hide() { + this.div.style('display', 'none'); + } }); diff --git a/escher/js/src/TextEditInput.js b/escher/js/src/TextEditInput.js index 41a0057b..e5a53902 100644 --- a/escher/js/src/TextEditInput.js +++ b/escher/js/src/TextEditInput.js @@ -1,11 +1,17 @@ -define(['utils', 'PlacedDiv'], function(utils, PlacedDiv) { +define(['utils', 'PlacedDiv', 'Map', 'ZoomContainer', 'CallbackManager', 'build'], function(utils, PlacedDiv, Map, ZoomContainer, CallbackManager, build) { /** */ var TextEditInput = utils.make_class(); // instance methods TextEditInput.prototype = { init: init, - is_visible: is_visible }; + setup_map_callbacks: setup_map_callbacks, + setup_zoom_callbacks: setup_zoom_callbacks, + is_visible: is_visible, + show: show, + hide: hide, + _accept_changes: _accept_changes, + _add_and_edit: _add_and_edit }; return TextEditInput; @@ -13,11 +19,135 @@ define(['utils', 'PlacedDiv'], function(utils, PlacedDiv) { function init(selection, map, zoom_container) { var div = selection.append('div') .attr('id', 'text-edit-input'); - this.placed_div = PlacedDiv(div); - div.append('input').style('display', 'none'); + this.placed_div = PlacedDiv(div, map); + this.placed_div.hide(); + this.input = div.append('input'); + + if (map instanceof Map) { + this.map = map; + this.setup_map_callbacks(map); + } else { + throw new Error('Cannot set the map. It is not an instance of ' + + 'Map'); + } + if (zoom_container instanceof ZoomContainer) { + this.zoom_container = zoom_container; + this.setup_zoom_callbacks(zoom_container); + } else { + throw new Error('Cannot set the zoom_container. It is not an ' + + 'instance of ZoomContainer'); + } + } + + function setup_map_callbacks(map) { + // input + map.callback_manager.set('edit_text_label.text_edit_input', function(target, coords) { + this.show(target, coords); + }.bind(this)); + + // new text_label + map.callback_manager.set('new_text_label.text_edit_input', function(coords) { + if (this.active_target !== null) + this._accept_changes(this.active_target.target); + this.hide(); + this._add_and_edit(coords); + }.bind(this)); + } + + function setup_zoom_callbacks(zoom_container) { + zoom_container.callback_manager.set('zoom.text_edit_input', function() { + if (this.active_target) + this._accept_changes(this.active_target.target); + this.hide(); + }.bind(this)); + zoom_container.callback_manager.set('go_to.text_edit_input', function() { + if (this.active_target) + this._accept_changes(this.active_target.target); + this.hide(); + }.bind(this)); } function is_visible() { return this.placed_div.is_visible(); } + + function show(target, coords) { + // save any existing edit + if (this.active_target) { + this._accept_changes(this.active_target.target); + } + + // set the current target + this.active_target = { target: target, + coords: coords }; + + // set the new value + target.each(function(d) { + this.input.node().value = d.text; + }.bind(this)); + + // place the input + this.placed_div.place(coords); + this.input.node().focus(); + + // escape key + this.escape = this.map.key_manager + .add_escape_listener(function() { + this.hide(); + }.bind(this)); + // enter key + this.enter = this.map.key_manager + .add_enter_listener(function(target) { + this._accept_changes(target); + this.hide(); + }.bind(this, target)); + } + + function hide() { + // hide the input + this.placed_div.hide(); + + // clear the value + this.input.attr('value', ''); + this.active_target = null; + + // clear escape + if (this.escape) + this.escape.clear(); + this.escape = null; + // clear enter + if (this.enter) + this.enter.clear(); + this.enter = null; + // turn off click listener + // this.map.sel.on('click.', null); + } + + function _accept_changes(target) { + if (this.input.node().value == '') { + // delete the label + target.each(function(d) { + var selected = {}; + selected[d.text_label_id] = this.map.text_labels[d.text_label_id]; + this.map.delete_selectable({}, selected, true); + }.bind(this)); + } else { + // set the text + var text_label_ids = []; + target.each(function(d) { + this.map.edit_text_label(d.text_label_id, this.input.node().value, true); + text_label_ids.push(d.text_label_id); + }.bind(this)); + } + } + + function _add_and_edit(coords) { + var out = build.new_text_label(this.map.largest_ids, '', coords); + this.map.text_labels[out.id] = out.label; + sel = this.map.draw_these_text_labels([out.id]); + // TODO wait here? + var sel = this.map.sel.select('#text-labels').selectAll('.text-label') + .filter(function(d) { return d.text_label_id==out.id; }); + this.show(sel, coords); + } }); diff --git a/escher/js/src/ZoomContainer.js b/escher/js/src/ZoomContainer.js index 23be14c0..79e050c7 100644 --- a/escher/js/src/ZoomContainer.js +++ b/escher/js/src/ZoomContainer.js @@ -165,6 +165,8 @@ define(["utils", "CallbackManager"], function(utils, CallbackManager) { move_this.attr('transform', 'translate('+this.window_translate.x+','+this.window_translate.y+')'+ 'scale('+this.window_scale+')'); + + this.callback_manager.run('go_to'); return null; } diff --git a/escher/js/src/build.js b/escher/js/src/build.js index 4c1e40f9..04f76813 100644 --- a/escher/js/src/build.js +++ b/escher/js/src/build.js @@ -1,7 +1,8 @@ define(["utils"], function(utils) { return { new_reaction: new_reaction, rotate_nodes: rotate_nodes, - move_node_and_dependents: move_node_and_dependents }; + move_node_and_dependents: move_node_and_dependents, + new_text_label: new_text_label }; // definitions function new_reaction(bigg_id, cobra_reaction, cobra_metabolites, @@ -422,4 +423,12 @@ define(["utils"], function(utils) { loc.circle = utils.c_plus_c(displacement, circle); return loc; } + + function new_text_label(largest_ids, text, coords) { + var new_id = String(++largest_ids.text_labels), + new_label = { text: text, + x: coords.x, + y: coords.y }; + return {id: new_id, label: new_label}; + } }); diff --git a/escher/js/src/draw.js b/escher/js/src/draw.js index fe8e8391..b8920a89 100644 --- a/escher/js/src/draw.js +++ b/escher/js/src/draw.js @@ -532,10 +532,10 @@ define(['utils', 'data_styles'], function(utils, data_styles) { utils.check_undefined(arguments, ['enter_selection']); enter_selection.append('g') + .attr('id', function(d) { return 'l'+d.text_label_id; }) .attr('class', 'text-label') .append('text') - .attr('class', 'label') - .text(function(d) { return d.text; }); + .attr('class', 'label'); } function update_text_label(update_selection, label_click, label_drag_behavior) { @@ -543,6 +543,7 @@ define(['utils', 'data_styles'], function(utils, data_styles) { update_selection .select('.label') + .text(function(d) { return d.text; }) .attr('transform', function(d) { return 'translate('+d.x+','+d.y+')';}) .on('click', label_click) .call(turn_off_drag) diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index f27cd5c3..73d39e73 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1936,10 +1936,10 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { utils.check_undefined(arguments, ['enter_selection']); enter_selection.append('g') + .attr('id', function(d) { return 'l'+d.text_label_id; }) .attr('class', 'text-label') .append('text') - .attr('class', 'label') - .text(function(d) { return d.text; }); + .attr('class', 'label'); } function update_text_label(update_selection, label_click, label_drag_behavior) { @@ -1947,6 +1947,7 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { update_selection .select('.label') + .text(function(d) { return d.text; }) .attr('transform', function(d) { return 'translate('+d.x+','+d.y+')';}) .on('click', label_click) .call(turn_off_drag) @@ -1974,7 +1975,8 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { define('build',["utils"], function(utils) { return { new_reaction: new_reaction, rotate_nodes: rotate_nodes, - move_node_and_dependents: move_node_and_dependents }; + move_node_and_dependents: move_node_and_dependents, + new_text_label: new_text_label }; // definitions function new_reaction(bigg_id, cobra_reaction, cobra_metabolites, @@ -2395,6 +2397,14 @@ define('build',["utils"], function(utils) { loc.circle = utils.c_plus_c(displacement, circle); return loc; } + + function new_text_label(largest_ids, text, coords) { + var new_id = String(++largest_ids.text_labels), + new_label = { text: text, + x: coords.x, + y: coords.y }; + return {id: new_id, label: new_label}; + } }); define('Behavior',["utils", "build"], function(utils, build) { @@ -2499,7 +2509,7 @@ define('Behavior',["utils", "build"], function(utils, build) { var selected_nodes = this.map.get_selected_nodes(); if (Object.keys(selected_nodes).length == 0) { - console.log('No selected nodes'); + console.warn('No selected nodes'); return; } @@ -2662,17 +2672,25 @@ define('Behavior',["utils", "build"], function(utils, build) { // run the callback var coords_a = d3.transform(d3.select(this).attr('transform')).translate, coords = {x: coords_a[0], y: coords_a[1]}; - map.callback_manager.run('edit_text_label', coords); + map.callback_manager.run('edit_text_label', d3.select(this), coords); d3.event.stopPropagation(); }; this.map.sel.select('#text-labels') .selectAll('.label') .classed('edit-text-cursor', true); + // add the new-label listener + this.map.sel.on('click.new_text_label', function(node) { + var coords = { x: d3.mouse(node)[0], + y: d3.mouse(node)[1] }; + this.map.callback_manager.run('new_text_label', coords); + }.bind(this, this.map.sel.node())); } else { this.text_label_click = this.selectable_click; this.map.sel.select('#text-labels') .selectAll('.label') .classed('edit-text-cursor', false); + // remove the new-label listener + this.map.sel.on('click.new_text_label', null); } } @@ -2735,7 +2753,7 @@ define('Behavior',["utils", "build"], function(utils, build) { total_displacement = {x: 0, y: 0}; // If a text label is selected, the rest is not necessary - if (d3.select(this).attr('class').indexOf('text-label')==-1) { + if (d3.select(this).attr('class').indexOf('label')==-1) { // Note that dragstart is called even for a click event var data = this.parentNode.__data__, bigg_id = data.bigg_id, @@ -2765,13 +2783,13 @@ define('Behavior',["utils", "build"], function(utils, build) { behavior.on("drag", function() { // get the grabbed id var grabbed = {}; - if (d3.select(this).attr('class').indexOf('text-label')==-1) { + if (d3.select(this).attr('class').indexOf('label')==-1) { // if it is a node grabbed['type'] = 'node'; grabbed['id'] = this.parentNode.__data__.node_id; } else { // if it is a text label - grabbed['type'] = 'text-label'; + grabbed['type'] = 'label'; grabbed['id'] = this.__data__.text_label_id; } @@ -2782,7 +2800,7 @@ define('Behavior',["utils", "build"], function(utils, build) { if (grabbed['type']=='node' && selected_node_ids.indexOf(grabbed['id'])==-1) { node_ids_to_drag.push(grabbed['id']); - } else if (grabbed['type']=='text-label' && + } else if (grabbed['type']=='label' && selected_text_label_ids.indexOf(grabbed['id'])==-1) { text_label_ids_to_drag.push(grabbed['id']); } else { @@ -6902,6 +6920,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb make_selected_node_primary: make_selected_node_primary, extend_nodes: extend_nodes, extend_reactions: extend_reactions, + edit_text_label: edit_text_label, // delete delete_selected: delete_selected, delete_selectable: delete_selectable, @@ -7481,6 +7500,9 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb sel.exit(); } function draw_these_text_labels(text_label_ids) { + /** Draw labels with the given ids. + + */ var text_labels = this.text_labels, text_label_click = this.behavior.text_label_click, text_label_drag = this.behavior.selectable_drag; @@ -7837,12 +7859,19 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb selected_text_labels = this.get_selected_text_labels(); if (Object.keys(selected_nodes).length >= 1 || Object.keys(selected_text_labels).length >= 1) - this.delete_selectable(selected_nodes, selected_text_labels); + this.delete_selectable(selected_nodes, selected_text_labels, true); } - function delete_selectable(selected_nodes, selected_text_labels) { - /** Delete the nodes and associated segments and reactions. + function delete_selectable(selected_nodes, selected_text_labels, should_draw) { + /** Delete the nodes and associated segments and reactions. Undoable. - Undoable. + Arguments + --------- + + selected_nodes: An object that is a subset of map.nodes. + + selected_text_labels: An object that is a subset of map.text_labels. + + should_draw: A boolean argument to determine whether to draw the changes to the map. */ var out = this.segments_and_reactions_for_nodes(selected_nodes), @@ -7870,7 +7899,7 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb // redraw // TODO just redraw these nodes, segments, and labels - this.draw_everything(); + if (should_draw) this.draw_everything(); }.bind(this); // delete @@ -7909,19 +7938,21 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb if (scale_changed) this.draw_all_reactions(); else this.draw_these_reactions(reaction_ids_to_draw); } else { - this.draw_these_reactions(reaction_ids_to_draw); + if (should_draw) this.draw_these_reactions(reaction_ids_to_draw); } if (this.has_metabolite_data()) { var scale_changed = this.update_metabolite_data_domain(); - if (scale_changed) this.draw_all_nodes(); - else this.draw_these_nodes(Object.keys(saved_nodes)); + if (should_draw) { + if (scale_changed) this.draw_all_nodes(); + else this.draw_these_nodes(Object.keys(saved_nodes)); + } } else { - this.draw_these_nodes(Object.keys(saved_nodes)); + if (should_draw) this.draw_these_nodes(Object.keys(saved_nodes)); } // redraw the saved text_labels utils.extend(this.text_labels, saved_text_labels); - this.draw_these_text_labels(Object.keys(saved_text_labels)); + if (should_draw) this.draw_these_text_labels(Object.keys(saved_text_labels)); // copy text_labels to re-delete selected_text_labels = utils.clone(saved_text_labels); @@ -8125,6 +8156,26 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb utils.extend(this.reactions, new_reactions); } + function edit_text_label(text_label_id, new_value, should_draw) { + // save old value + var saved_value = this.text_labels[text_label_id].text, + edit_and_draw = function(new_val, should_draw) { + // set the new value + this.text_labels[text_label_id].text = new_val; + if (should_draw) this.draw_these_text_labels([text_label_id]); + }.bind(this); + + // edit the label + edit_and_draw(new_value, should_draw); + + // add to undo stack + this.undo_stack.push(function() { + edit_and_draw(saved_value, should_draw); + }, function () { + edit_and_draw(new_value, should_draw); + }); + } + function new_reaction_for_metabolite(reaction_bigg_id, selected_node_id, direction) { /** Build a new reaction starting with selected_met. @@ -8507,7 +8558,6 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb // IO function save() { - console.log("Saving"); utils.download_json(this.map_for_export(), "saved_map"); } function map_for_export() { @@ -8549,7 +8599,6 @@ define('Map',["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "Callb return out; } function save_svg() { - console.log("Exporting SVG"); this.callback_manager.run('before_svg_export'); // turn of zoom and translate so that illustrator likes the map var window_scale = this.zoom_container.window_scale, @@ -8583,32 +8632,27 @@ define('PlacedDiv',['utils', 'Map'], function(utils, Map) { var PlacedDiv = utils.make_class(); // instance methods PlacedDiv.prototype = { init: init, - show: show, - hide: hide, is_visible: is_visible, - place: place }; + place: place, + hide: hide }; return PlacedDiv; // definitions - function init(div, map) { + function init(div, map, displacement) { // make the input box this.div = div; + if (displacement===undefined) + displacement = {x: 0, y: 0}; + this.displacement = displacement; + if (map instanceof Map) { this.map = map; } else { - console.error('Cannot set the map. It is not an instance of builder/Map'); + throw new Error('Cannot set the map. It is not an instance of Map'); } } - function show() { - this.div.style('display', null); - } - - function hide() { - this.div.style('display', 'none'); - } - function is_visible() { return this.div.style('display') != 'none'; } @@ -8617,22 +8661,28 @@ define('PlacedDiv',['utils', 'Map'], function(utils, Map) { /** Position the html div to match the given SVG coordinates. */ + // show the input + this.div.style('display', null); + // move the new input - var d = {x: 240, y: 0}, - window_translate = this.map.zoom_container.window_translate, + var window_translate = this.map.zoom_container.window_translate, window_scale = this.map.zoom_container.window_scale, map_size = this.map.get_size(), left = Math.max(20, Math.min(map_size.width - 270, - (window_scale * coords.x + window_translate.x - d.x))), + (window_scale * coords.x + window_translate.x - this.displacement.x))), top = Math.max(20, Math.min(map_size.height - 40, - (window_scale * coords.y + window_translate.y - d.y))); + (window_scale * coords.y + window_translate.y - this.displacement.y))); this.div.style('position', 'absolute') .style('display', 'block') .style('left', left+'px') .style('top', top+'px'); } + + function hide() { + this.div.style('display', 'none'); + } }); /** @@ -9208,6 +9258,8 @@ define('ZoomContainer',["utils", "CallbackManager"], function(utils, CallbackMan move_this.attr('transform', 'translate('+this.window_translate.x+','+this.window_translate.y+')'+ 'scale('+this.window_scale+')'); + + this.callback_manager.run('go_to'); return null; } @@ -9420,7 +9472,8 @@ define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContai function init(selection, map, zoom_container) { // set up container var new_sel = selection.append('div').attr('id', 'rxn-input'); - this.placed_div = PlacedDiv(new_sel); + this.placed_div = PlacedDiv(new_sel, map, {x: 240, y: 0}); + this.placed_div.hide(); // set up complete.ly var c = completely(new_sel.node(), { backgroundColor: '#eee' }); d3.select(c.input) @@ -9435,7 +9488,8 @@ define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContai this.completely = c; // close button new_sel.append('button').attr('class', "button input-close-button") - .text("×").on('click', function() { this.hide_dropdown(); }.bind(this)); + .text("×") + .on('click', function() { this.hide_dropdown(); }.bind(this)); if (map instanceof Map) { this.map = map; @@ -9447,23 +9501,22 @@ define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContai this.setup_map_callbacks(map); } else { - console.error('Cannot set the map. It is not an instance of builder/Map'); + throw new Error('Cannot set the map. It is not an instance of ' + + 'Map'); } if (zoom_container instanceof ZoomContainer) { this.zoom_container = zoom_container; - this.setup_zoom_callbacks(); + this.setup_zoom_callbacks(zoom_container); } else { - console.error('Cannot set the zoom_container. It is not an instance of ' + - 'builder/ZoomContainer'); + throw new Error('Cannot set the zoom_container. It is not an ' + + 'instance of ZoomContainer'); } - // set up reaction input callbacks - this.callback_manager = new CallbackManager(); - // toggle off this.toggle(false); this.target_coords = null; } + function setup_map_callbacks(map) { // input map.callback_manager.set('select_metabolite_with_id.input', function(selected_node, coords) { @@ -9485,8 +9538,9 @@ define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContai this.hide_target(); }.bind(this)); } - function setup_zoom_callbacks() { - this.zoom_container.callback_manager.set('zoom.input', function() { + + function setup_zoom_callbacks(zoom_container) { + zoom_container.callback_manager.set('zoom.input', function() { if (this.is_active) { this.place_at_selected(); } @@ -10733,14 +10787,20 @@ define('SettingsBar',["utils", "CallbackManager", "lib/bacon"], function(utils, } }); -define('TextEditInput',['utils', 'PlacedDiv'], function(utils, PlacedDiv) { +define('TextEditInput',['utils', 'PlacedDiv', 'Map', 'ZoomContainer', 'CallbackManager', 'build'], function(utils, PlacedDiv, Map, ZoomContainer, CallbackManager, build) { /** */ var TextEditInput = utils.make_class(); // instance methods TextEditInput.prototype = { init: init, - is_visible: is_visible }; + setup_map_callbacks: setup_map_callbacks, + setup_zoom_callbacks: setup_zoom_callbacks, + is_visible: is_visible, + show: show, + hide: hide, + _accept_changes: _accept_changes, + _add_and_edit: _add_and_edit }; return TextEditInput; @@ -10748,13 +10808,137 @@ define('TextEditInput',['utils', 'PlacedDiv'], function(utils, PlacedDiv) { function init(selection, map, zoom_container) { var div = selection.append('div') .attr('id', 'text-edit-input'); - this.placed_div = PlacedDiv(div); - div.append('input').style('display', 'none'); + this.placed_div = PlacedDiv(div, map); + this.placed_div.hide(); + this.input = div.append('input'); + + if (map instanceof Map) { + this.map = map; + this.setup_map_callbacks(map); + } else { + throw new Error('Cannot set the map. It is not an instance of ' + + 'Map'); + } + if (zoom_container instanceof ZoomContainer) { + this.zoom_container = zoom_container; + this.setup_zoom_callbacks(zoom_container); + } else { + throw new Error('Cannot set the zoom_container. It is not an ' + + 'instance of ZoomContainer'); + } + } + + function setup_map_callbacks(map) { + // input + map.callback_manager.set('edit_text_label.text_edit_input', function(target, coords) { + this.show(target, coords); + }.bind(this)); + + // new text_label + map.callback_manager.set('new_text_label.text_edit_input', function(coords) { + if (this.active_target !== null) + this._accept_changes(this.active_target.target); + this.hide(); + this._add_and_edit(coords); + }.bind(this)); + } + + function setup_zoom_callbacks(zoom_container) { + zoom_container.callback_manager.set('zoom.text_edit_input', function() { + if (this.active_target) + this._accept_changes(this.active_target.target); + this.hide(); + }.bind(this)); + zoom_container.callback_manager.set('go_to.text_edit_input', function() { + if (this.active_target) + this._accept_changes(this.active_target.target); + this.hide(); + }.bind(this)); } function is_visible() { return this.placed_div.is_visible(); } + + function show(target, coords) { + // save any existing edit + if (this.active_target) { + this._accept_changes(this.active_target.target); + } + + // set the current target + this.active_target = { target: target, + coords: coords }; + + // set the new value + target.each(function(d) { + this.input.node().value = d.text; + }.bind(this)); + + // place the input + this.placed_div.place(coords); + this.input.node().focus(); + + // escape key + this.escape = this.map.key_manager + .add_escape_listener(function() { + this.hide(); + }.bind(this)); + // enter key + this.enter = this.map.key_manager + .add_enter_listener(function(target) { + this._accept_changes(target); + this.hide(); + }.bind(this, target)); + } + + function hide() { + // hide the input + this.placed_div.hide(); + + // clear the value + this.input.attr('value', ''); + this.active_target = null; + + // clear escape + if (this.escape) + this.escape.clear(); + this.escape = null; + // clear enter + if (this.enter) + this.enter.clear(); + this.enter = null; + // turn off click listener + // this.map.sel.on('click.', null); + } + + function _accept_changes(target) { + if (this.input.node().value == '') { + // delete the label + target.each(function(d) { + var selected = {}; + selected[d.text_label_id] = this.map.text_labels[d.text_label_id]; + this.map.delete_selectable({}, selected, true); + }.bind(this)); + } else { + // set the text + var text_label_ids = []; + target.each(function(d) { + this.map.edit_text_label(d.text_label_id, this.input.node().value, true); + text_label_ids.push(d.text_label_id); + }.bind(this)); + } + } + + function _add_and_edit(coords) { + var out = build.new_text_label(this.map.largest_ids, '', coords); + this.map.text_labels[out.id] = out.label; + sel = this.map.draw_these_text_labels([out.id]); + // TODO wait here? + var sel = this.map.sel.select('#text-labels').selectAll('.text-label') + .filter(function(d) { return d.text_label_id==out.id; }); + this.show(sel, coords); + } }); define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'CallbackManager', 'ui', 'SearchBar', 'Settings', 'SettingsBar', 'TextEditInput'], function(utils, BuildInput, ZoomContainer, Map, CobraModel, Brush, CallbackManager, ui, SearchBar, Settings, SettingsBar, TextEditInput) { diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 04b1c315..e01709e9 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("class","text-label").append("text").attr("class","label").text(function(e){return e.text})}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.log("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0)}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("text-label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("text-label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="text-label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="text-label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function m(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,get_selectable_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_generic_drag:v,get_generic_angular_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t)}function Z(t,n){var r=this.segments_and_reactions_for_nodes(t),i=r.reactions,s=r.segment_objs_w_segments,o=e.clone(t),u=e.clone(s),a=e.clone(i),f=e.clone(n),l=function(e,n,r,i){this.delete_node_data(Object.keys(t)),this.delete_segment_data(r),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(i)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),this.draw_everything()}.bind(this);l(t,i,s,n),this.undo_stack.push(function(){this.extend_nodes(o),this.extend_reactions(a);var r=Object.keys(a);u.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in o)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),r.indexOf(e.reaction_id)==-1&&r.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var l=this.update_reaction_data_domain();l?this.draw_all_reactions():this.draw_these_reactions(r)}else this.draw_these_reactions(r);if(this.has_metabolite_data()){var l=this.update_metabolite_data_domain();l?this.draw_all_nodes():this.draw_these_nodes(Object.keys(o))}else this.draw_these_nodes(Object.keys(o));e.extend(this.text_labels,f),this.draw_these_text_labels(Object.keys(f)),n=e.clone(f),t=e.clone(o),s=e.clone(u),i=e.clone(a)}.bind(this),function(){l(t,i,s,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ct(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function ht(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function pt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function dt(e){this._zoom_extent(e,"nodes")}function vt(e){this._zoom_extent(e,"canvas")}function mt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function gt(){return this.zoom_container.get_size()}function yt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function bt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function Et(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function St(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function xt(){console.log("Saving"),e.download_json(this.map_for_export(),"saved_map")}function Tt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Nt(){console.log("Exporting SVG"),this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:lt,cycle_primary_node:ct,make_selected_node_primary:ht,extend_nodes:at,extend_reactions:ft,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:pt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:dt,zoom_extent_canvas:vt,_zoom_extent:mt,get_size:gt,zoom_to_reaction:yt,zoom_to_node:bt,highlight_reaction:wt,highlight_node:Et,highlight:St,save:xt,map_for_export:Tt,save_svg:Nt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n){this.div=e,n instanceof t?this.map=n:console.error("Cannot set the map. It is not an instance of builder/Map")}function i(){this.div.style("display",null)}function s(){this.div.style("display","none")}function o(){return this.div.style("display")!="none"}function u(e){var t={x:240,y:0},n=this.map.zoom_container.window_translate,r=this.map.zoom_container.window_scale,i=this.map.get_size(),s=Math.max(20,Math.min(i.width-270,r*e.x+n.x-t.x)),o=Math.max(20,Math.min(i.height-40,r*e.y+n.y-t.y));this.div.style("position","absolute").style("display","block").style("left",s+"px").style("top",o+"px")}var n=e.make_class();return n.prototype={init:r,show:i,hide:s,is_visible:o,place:u},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,o,a){var f=e.append("div").attr("id","rxn-input");this.placed_div=t(f);var l=n(f.node(),{backgroundColor:"#eee"});d3.select(l.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=l,f.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(o instanceof r){this.map=o;var c=90;this.direction_arrow=new u(o.sel),this.direction_arrow.set_rotation(c),this.setup_map_callbacks(o)}else console.error("Cannot set the map. It is not an instance of builder/Map");a instanceof i?(this.zoom_container=a,this.setup_zoom_callbacks()):console.error("Cannot set the zoom_container. It is not an instance of builder/ZoomContainer"),this.callback_manager=new s,this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(){this.zoom_container.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_selection.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_selection.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_selection.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function m(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,get_selectable_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_generic_drag:v,get_generic_angular_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function Z(t,n,r){var i=this.segments_and_reactions_for_nodes(t),s=i.reactions,o=i.segment_objs_w_segments,u=e.clone(t),a=e.clone(o),f=e.clone(s),l=e.clone(n),c=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&this.draw_everything()}.bind(this);c(t,s,o,n),this.undo_stack.push(function(){this.extend_nodes(u),this.extend_reactions(f);var i=Object.keys(f);a.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in u)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),i.indexOf(e.reaction_id)==-1&&i.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var c=this.update_reaction_data_domain();c?this.draw_all_reactions():this.draw_these_reactions(i)}else r&&this.draw_these_reactions(i);if(this.has_metabolite_data()){var c=this.update_metabolite_data_domain();r&&(c?this.draw_all_nodes():this.draw_these_nodes(Object.keys(u)))}else r&&this.draw_these_nodes(Object.keys(u));e.extend(this.text_labels,l),r&&this.draw_these_text_labels(Object.keys(l)),n=e.clone(l),t=e.clone(u),o=e.clone(a),s=e.clone(f)}.bind(this),function(){c(t,s,o,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function ct(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ht(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function pt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function dt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function vt(e){this._zoom_extent(e,"nodes")}function mt(e){this._zoom_extent(e,"canvas")}function gt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function yt(){return this.zoom_container.get_size()}function bt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Et(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function St(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function xt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function Tt(){e.download_json(this.map_for_export(),"saved_map")}function Nt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Ct(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:ct,cycle_primary_node:ht,make_selected_node_primary:pt,extend_nodes:at,extend_reactions:ft,edit_text_label:lt,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:dt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:vt,zoom_extent_canvas:mt,_zoom_extent:gt,get_size:yt,zoom_to_reaction:bt,zoom_to_node:wt,highlight_reaction:Et,highlight_node:St,highlight:xt,save:Tt,map_for_export:Nt,save_svg:Ct},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_selection.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_selection.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_selection.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Wed, 20 Aug 2014 19:22:27 -0400 Subject: [PATCH 08/33] Fixed bug: incorrect placed_div name in build input --- escher/js/src/BuildInput.js | 21 +++------------------ escher/lib/escher.1.0.0b3.js | 21 +++------------------ escher/lib/escher.1.0.0b3.min.js | 2 +- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/escher/js/src/BuildInput.js b/escher/js/src/BuildInput.js index ddcd0551..a8857107 100644 --- a/escher/js/src/BuildInput.js +++ b/escher/js/src/BuildInput.js @@ -129,14 +129,14 @@ define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'Callba } } function show_dropdown(coords) { - this.placed_selection.show(); + this.placed_div.show(); this.completely.input.blur(); this.completely.repaint(); this.completely.setText(""); this.completely.input.focus(); } function hide_dropdown() { - this.placed_selection.hide(); + this.placed_div.hide(); this.completely.hideDropDown(); } function place_at_selected() { @@ -152,22 +152,7 @@ define(['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContainer', 'Callba this.place(coords); } function place(coords) { - this.placed_selection.place(coords); - // var d = {x: 240, y: 0}, - // window_translate = this.map.zoom_container.window_translate, - // window_scale = this.map.zoom_container.window_scale, - // map_size = this.map.get_size(); - // var left = Math.max(20, - // Math.min(map_size.width - 270, - // (window_scale * coords.x + window_translate.x - d.x))); - // var top = Math.max(20, - // Math.min(map_size.height - 40, - // (window_scale * coords.y + window_translate.y - d.y))); - // this.selection.style('position', 'absolute') - // .style('display', 'block') - // .style('left',left+'px') - // .style('top',top+'px'); - + this.placed_div.place(coords); this.direction_arrow.set_location(coords); this.direction_arrow.show(); } diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 73d39e73..3bd9fb08 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -9576,14 +9576,14 @@ define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContai } } function show_dropdown(coords) { - this.placed_selection.show(); + this.placed_div.show(); this.completely.input.blur(); this.completely.repaint(); this.completely.setText(""); this.completely.input.focus(); } function hide_dropdown() { - this.placed_selection.hide(); + this.placed_div.hide(); this.completely.hideDropDown(); } function place_at_selected() { @@ -9599,22 +9599,7 @@ define('BuildInput',['utils', 'PlacedDiv', 'lib/complete.ly', 'Map', 'ZoomContai this.place(coords); } function place(coords) { - this.placed_selection.place(coords); - // var d = {x: 240, y: 0}, - // window_translate = this.map.zoom_container.window_translate, - // window_scale = this.map.zoom_container.window_scale, - // map_size = this.map.get_size(); - // var left = Math.max(20, - // Math.min(map_size.width - 270, - // (window_scale * coords.x + window_translate.x - d.x))); - // var top = Math.max(20, - // Math.min(map_size.height - 40, - // (window_scale * coords.y + window_translate.y - d.y))); - // this.selection.style('position', 'absolute') - // .style('display', 'block') - // .style('left',left+'px') - // .style('top',top+'px'); - + this.placed_div.place(coords); this.direction_arrow.set_location(coords); this.direction_arrow.show(); } diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index e01709e9..a25086a8 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function m(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,get_selectable_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_generic_drag:v,get_generic_angular_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function Z(t,n,r){var i=this.segments_and_reactions_for_nodes(t),s=i.reactions,o=i.segment_objs_w_segments,u=e.clone(t),a=e.clone(o),f=e.clone(s),l=e.clone(n),c=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&this.draw_everything()}.bind(this);c(t,s,o,n),this.undo_stack.push(function(){this.extend_nodes(u),this.extend_reactions(f);var i=Object.keys(f);a.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in u)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),i.indexOf(e.reaction_id)==-1&&i.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var c=this.update_reaction_data_domain();c?this.draw_all_reactions():this.draw_these_reactions(i)}else r&&this.draw_these_reactions(i);if(this.has_metabolite_data()){var c=this.update_metabolite_data_domain();r&&(c?this.draw_all_nodes():this.draw_these_nodes(Object.keys(u)))}else r&&this.draw_these_nodes(Object.keys(u));e.extend(this.text_labels,l),r&&this.draw_these_text_labels(Object.keys(l)),n=e.clone(l),t=e.clone(u),o=e.clone(a),s=e.clone(f)}.bind(this),function(){c(t,s,o,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function ct(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ht(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function pt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function dt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function vt(e){this._zoom_extent(e,"nodes")}function mt(e){this._zoom_extent(e,"canvas")}function gt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function yt(){return this.zoom_container.get_size()}function bt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Et(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function St(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function xt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function Tt(){e.download_json(this.map_for_export(),"saved_map")}function Nt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Ct(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:ct,cycle_primary_node:ht,make_selected_node_primary:pt,extend_nodes:at,extend_reactions:ft,edit_text_label:lt,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:dt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:vt,zoom_extent_canvas:mt,_zoom_extent:gt,get_size:yt,zoom_to_reaction:bt,zoom_to_node:wt,highlight_reaction:Et,highlight_node:St,highlight:xt,save:Tt,map_for_export:Nt,save_svg:Ct},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_selection.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_selection.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_selection.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function m(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,get_selectable_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_generic_drag:v,get_generic_angular_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function Z(t,n,r){var i=this.segments_and_reactions_for_nodes(t),s=i.reactions,o=i.segment_objs_w_segments,u=e.clone(t),a=e.clone(o),f=e.clone(s),l=e.clone(n),c=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&this.draw_everything()}.bind(this);c(t,s,o,n),this.undo_stack.push(function(){this.extend_nodes(u),this.extend_reactions(f);var i=Object.keys(f);a.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in u)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),i.indexOf(e.reaction_id)==-1&&i.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var c=this.update_reaction_data_domain();c?this.draw_all_reactions():this.draw_these_reactions(i)}else r&&this.draw_these_reactions(i);if(this.has_metabolite_data()){var c=this.update_metabolite_data_domain();r&&(c?this.draw_all_nodes():this.draw_these_nodes(Object.keys(u)))}else r&&this.draw_these_nodes(Object.keys(u));e.extend(this.text_labels,l),r&&this.draw_these_text_labels(Object.keys(l)),n=e.clone(l),t=e.clone(u),o=e.clone(a),s=e.clone(f)}.bind(this),function(){c(t,s,o,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function ct(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ht(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function pt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function dt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function vt(e){this._zoom_extent(e,"nodes")}function mt(e){this._zoom_extent(e,"canvas")}function gt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function yt(){return this.zoom_container.get_size()}function bt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Et(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function St(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function xt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function Tt(){e.download_json(this.map_for_export(),"saved_map")}function Nt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Ct(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:ct,cycle_primary_node:ht,make_selected_node_primary:pt,extend_nodes:at,extend_reactions:ft,edit_text_label:lt,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:dt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:vt,zoom_extent_canvas:mt,_zoom_extent:gt,get_size:yt,zoom_to_reaction:bt,zoom_to_node:wt,highlight_reaction:Et,highlight_node:St,highlight:xt,save:Tt,map_for_export:Nt,save_svg:Ct},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sat, 23 Aug 2014 23:09:22 -0700 Subject: [PATCH 09/33] Streamlined drawing; huge speedup for deletion; still separating beziers. --- escher/css/builder-embed.css | 2 +- escher/js/src/Map.js | 470 +++++++++++++++++++---------------- escher/js/src/build.js | 46 +++- escher/js/src/draw.js | 210 +++++++--------- escher/js/src/utils.js | 51 ++-- 5 files changed, 426 insertions(+), 353 deletions(-) diff --git a/escher/css/builder-embed.css b/escher/css/builder-embed.css index 788219d3..6f58a0f3 100644 --- a/escher/css/builder-embed.css +++ b/escher/css/builder-embed.css @@ -64,7 +64,7 @@ stroke: #fff; shape-rendering: crispEdges; } -.bezier { +.bezier-circle { fill: rgb(255,255,255); } .bezier1 { diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index 5ef58ad7..d3f0d7f2 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -4,7 +4,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan Arguments --------- - svg: + svg: The parent SVG container for the map. css: @@ -79,24 +79,35 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan get_selected_text_labels: get_selected_text_labels, segments_and_reactions_for_nodes: segments_and_reactions_for_nodes, // draw - has_reaction_data: has_reaction_data, - has_metabolite_data: has_metabolite_data, draw_everything: draw_everything, + // draw reactions draw_all_reactions: draw_all_reactions, draw_these_reactions: draw_these_reactions, + clear_deleted_reactions: clear_deleted_reactions, + // draw nodes draw_all_nodes: draw_all_nodes, draw_these_nodes: draw_these_nodes, + clear_deleted_nodes: clear_deleted_nodes, + // draw text_labels + draw_all_text_labels: draw_all_text_labels, draw_these_text_labels: draw_these_text_labels, + clear_deleted_text_labels: clear_deleted_text_labels, + // draw beziers + draw_all_beziers: draw_all_beziers, + draw_these_beziers: draw_these_beziers, + clear_deleted_beziers: clear_deleted_beziers, + toggle_beziers: toggle_beziers, + hide_beziers: hide_beziers, + show_beziers: show_beziers, + // data + has_reaction_data: has_reaction_data, + has_metabolite_data: has_metabolite_data, apply_reaction_data_to_map: apply_reaction_data_to_map, apply_reaction_data_to_reactions: apply_reaction_data_to_reactions, update_reaction_data_domain: update_reaction_data_domain, apply_metabolite_data_to_map: apply_metabolite_data_to_map, apply_metabolite_data_to_nodes: apply_metabolite_data_to_nodes, update_metabolite_data_domain: update_metabolite_data_domain, - get_selected_node_ids: get_selected_node_ids, - toggle_beziers: toggle_beziers, - hide_beziers: hide_beziers, - show_beziers: show_beziers, // zoom zoom_extent_nodes: zoom_extent_nodes, zoom_extent_canvas: zoom_extent_canvas, @@ -195,6 +206,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.nodes = {}; this.reactions = {}; + this.beziers = {}; this.membranes = []; this.text_labels = {}; this.info = {}; @@ -240,7 +252,8 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan map.text_labels = map_data.text_labels; map.info = map_data.info; - // propogate coefficients and reversbility, and populate the search index + // Propogate coefficients and reversbility, and populate the reaction + // search index. for (var r_id in map.reactions) { var reaction = map.reactions[r_id]; if (enable_search) { @@ -259,7 +272,8 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan if (to_node_bigg_id in reaction.metabolites) { segment.to_node_coefficient = reaction.metabolites[to_node_bigg_id].coefficient; } - // if metabolite without beziers, then add them + + // If the metabolite has no bezier points, then add them. var start = map.nodes[segment.from_node_id], end = map.nodes[segment.to_node_id]; if (start['node_type']=='metabolite' || end['node_type']=='metabolite') { @@ -270,6 +284,8 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } } + + // populate the nodes search index. if (enable_search) { for (var node_id in map.nodes) { var node = map.nodes[node_id]; @@ -279,6 +295,10 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan node_id: node_id }}); } } + + // populate the beziers + map.beziers = build.beziers_for_reactions(map.reactions); + // get largest ids for adding new reactions, nodes, text labels, and // segments map.largest_ids.reactions = get_largest_id(map.reactions); @@ -313,28 +333,28 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // more setup function setup_containers(sel) { + sel.append('g') + .attr('id', 'reactions'); sel.append('g') .attr('id', 'nodes'); sel.append('g') - .attr('id', 'reactions'); + .attr('id', 'beziers'); sel.append('g') .attr('id', 'text-labels'); - sel.append('g') - .attr('id', 'membranes'); } function reset_containers() { + this.sel.select('#reactions') + .selectAll('.reaction') + .remove(); this.sel.select('#nodes') .selectAll('.node') .remove(); - this.sel.select('#reactions') - .selectAll('.reaction') + this.sel.select('#beziers') + .selectAll('.bezier') .remove(); this.sel.select('#text-labels') .selectAll('.text-label') .remove(); - this.sel.select('#membranes') - .selectAll('.membrane') - .remove(); } // ------------------------------------------------------------------------- @@ -461,6 +481,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } function clear_map() { this.reactions = {}; + this.beziers = {}; this.nodes = {}; this.membranes = []; this.text_labels = {}; @@ -476,216 +497,257 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan return (this.metabolite_data_object!==null); } function draw_everything() { - /** Draw the reactions and membranes + /** Draw the all reactions, nodes, & text labels. */ - var sel = this.sel, - membranes = this.membranes, - scale = this.scale, - reactions = this.reactions, - nodes = this.nodes, - text_labels = this.text_labels, - defs = this.defs, - default_reaction_color = this.default_reaction_color, - bezier_drag_behavior = this.behavior.bezier_drag, - node_click_fn = this.behavior.selectable_click, - node_mouseover_fn = this.behavior.node_mouseover, - node_mouseout_fn = this.behavior.node_mouseout, - node_drag_behavior = this.behavior.selectable_drag, - reaction_label_drag = this.behavior.reaction_label_drag, - node_label_drag = this.behavior.node_label_drag, - text_label_click = this.behavior.text_label_click, - text_label_drag = this.behavior.selectable_drag, - has_reaction_data = this.has_reaction_data(), - reaction_data_styles = this.settings.data_styles['reaction'], - has_metabolite_data = this.has_metabolite_data(), - metabolite_data_styles = this.settings.data_styles['metabolite'], - beziers_enabled = this.beziers_enabled; - - utils.draw_an_array(sel, '#membranes' ,'.membrane', membranes, - draw.create_membrane, - draw.update_membrane); - - utils.draw_an_object(sel, '#reactions', '.reaction', reactions, - 'reaction_id', - draw.create_reaction, - function(sel) { return draw.update_reaction(sel, - scale, - nodes, - beziers_enabled, - defs, - default_reaction_color, - has_reaction_data, - reaction_data_styles, - bezier_drag_behavior, - reaction_label_drag); }); - - utils.draw_an_object(sel, '#nodes', '.node', nodes, 'node_id', - function(sel) { return draw.create_node(sel, nodes, reactions); }, - function(sel) { return draw.update_node(sel, scale, - has_metabolite_data, - metabolite_data_styles, - node_click_fn, - node_mouseover_fn, - node_mouseout_fn, - node_drag_behavior, - node_label_drag); }); - - utils.draw_an_object(sel, '#text-labels', '.text-label', text_labels, - 'text_label_id', - function(sel) { return draw.create_text_label(sel); }, - function(sel) { return draw.update_text_label(sel, - text_label_click, - text_label_drag); }); - - + this.draw_all_reactions(); + this.draw_all_nodes(); + this.draw_all_text_labels(); } function draw_all_reactions() { + /** Draw all reactions, and clear deleted reactions. + + */ + // Draw all reactions. var reaction_ids = []; for (var reaction_id in this.reactions) { reaction_ids.push(reaction_id); } this.draw_these_reactions(reaction_ids); + + // Clear all deleted reactions. + this.clear_deleted_reactions(); } + function draw_these_reactions(reaction_ids) { - var scale = this.scale, - reactions = this.reactions, - nodes = this.nodes, - defs = this.defs, - default_reaction_color = this.default_reaction_color, - bezier_drag_behavior = this.behavior.bezier_drag, - reaction_label_drag = this.behavior.reaction_label_drag, - has_reaction_data = this.has_reaction_data(), - reaction_data_styles = this.settings.data_styles['reaction'], - beziers_enabled = this.beziers_enabled; + /** Draw specific reactions. + Does nothing with exit selection. Use clear_deleted_reactions to remove + reactions from the DOM. + + Arguments + --------- + + reactions_ids: An array of reaction_ids to update. + + */ // find reactions for reaction_ids - var reaction_subset = {}, - i = -1; - while (++i Date: Fri, 5 Sep 2014 11:09:15 -0700 Subject: [PATCH 10/33] Beziers have their own layer. Still unfinished. See Map.js#L1131. --- escher/css/builder-embed.css | 4 +- escher/js/src/Behavior.js | 119 ++++++++++++++++++++---------- escher/js/src/Builder.js | 1 + escher/js/src/Map.js | 130 +++++++++++++++++++++++++-------- escher/js/src/build.js | 138 ++++++++++++++++++++++++----------- escher/js/src/draw.js | 120 +++++++++++------------------- escher/js/src/utils.js | 63 ++++++++++++++++ 7 files changed, 384 insertions(+), 191 deletions(-) diff --git a/escher/css/builder-embed.css b/escher/css/builder-embed.css index 6f58a0f3..2406a78e 100644 --- a/escher/css/builder-embed.css +++ b/escher/css/builder-embed.css @@ -67,10 +67,10 @@ .bezier-circle { fill: rgb(255,255,255); } -.bezier1 { +.bezier-circle.b1 { stroke: red; } -.bezier2 { +.bezier-circle.b2 { stroke: blue; } .connect-line{ diff --git a/escher/js/src/Behavior.js b/escher/js/src/Behavior.js index 551bf2a0..e22bc0ca 100644 --- a/escher/js/src/Behavior.js +++ b/escher/js/src/Behavior.js @@ -32,13 +32,14 @@ define(["utils", "build"], function(utils, build) { toggle_text_label_edit: toggle_text_label_edit, toggle_selectable_drag: toggle_selectable_drag, toggle_label_drag: toggle_label_drag, + toggle_bezier_drag: toggle_bezier_drag, // get drag behaviors - get_selectable_drag: get_selectable_drag, - get_bezier_drag: get_bezier_drag, - get_reaction_label_drag: get_reaction_label_drag, - get_node_label_drag: get_node_label_drag, - get_generic_drag: get_generic_drag, - get_generic_angular_drag: get_generic_angular_drag }; + _get_selectable_drag: _get_selectable_drag, + _get_bezier_drag: _get_bezier_drag, + _get_reaction_label_drag: _get_reaction_label_drag, + _get_node_label_drag: _get_node_label_drag, + _get_generic_drag: _get_generic_drag, + _get_generic_angular_drag: _get_generic_angular_drag }; return Behavior; @@ -61,13 +62,15 @@ define(["utils", "build"], function(utils, build) { this.node_mouseover = null; this.node_mouseout = null; this.bezier_drag = this.empty_behavior; + this.bezier_mouseover = null; + this.bezier_mouseout = null; this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; this.turn_everything_on(); } function turn_everything_on() { /** Toggle everything except rotation mode and text mode. - + */ this.toggle_selectable_click(true); this.toggle_selectable_drag(true); @@ -150,9 +153,9 @@ define(["utils", "build"], function(utils, build) { center_fn = function() { return this.center; }.bind(this); - this.rotation_drag = this.get_generic_angular_drag(start_fn, drag_fn, end_fn, - undo_fn, redo_fn, center_fn, - this.map.sel); + this.rotation_drag = this._get_generic_angular_drag(start_fn, drag_fn, end_fn, + undo_fn, redo_fn, center_fn, + this.map.sel); selection_background.call(this.rotation_drag); @@ -293,8 +296,8 @@ define(["utils", "build"], function(utils, build) { */ if (on_off===undefined) on_off = this.selectable_drag===this.empty_behavior; if (on_off) { - this.selectable_drag = this.get_selectable_drag(this.map, this.undo_stack); - this.bezier_drag = this.get_bezier_drag(this.map, this.undo_stack); + this.selectable_drag = this._get_selectable_drag(this.map, this.undo_stack); + this.bezier_drag = this._get_bezier_drag(this.map, this.undo_stack); } else { this.selectable_drag = this.empty_behavior; this.bezier_drag = this.empty_behavior; @@ -308,15 +311,43 @@ define(["utils", "build"], function(utils, build) { */ if (on_off===undefined) on_off = this.label_drag===this.empty_behavior; if (on_off) { - this.reaction_label_drag = this.get_reaction_label_drag(this.map); - this.node_label_drag = this.get_node_label_drag(this.map); + this.reaction_label_drag = this._get_reaction_label_drag(this.map); + this.node_label_drag = this._get_node_label_drag(this.map); } else { this.reaction_label_drag = this.empty_behavior; this.node_label_drag = this.empty_behavior; } } - function get_selectable_drag(map, undo_stack) { + function toggle_bezier_drag(on_off) { + /** With no argument, toggle the bezier drag on or off. + + Pass in a boolean argument to set the on/off state. + + */ + if (on_off===undefined) on_off = this.bezier_drag===this.empty_behavior; + if (on_off) { + this.bezier_drag = this._get_bezier_drag(this.map); + this.bezier_mouseover = function(d) { + d3.select(this).style('stroke-width', String(3)+'px'); + // d3.select(this.parentNode.parentNode) + // .selectAll('.connect-line') + // .attr('visibility', 'visible'); + }; + this.bezier_mouseout = function(d) { + d3.select(this).style('stroke-width', String(1)+'px'); + // d3.select(this.parentNode.parentNode) + // .selectAll('.connect-line') + // .attr('visibility', 'hidden'); + }; + } else { + this.bezier_drag = this.empty_behavior; + this.bezier_mouseover = null; + this.bezier_mouseout = null; + } + } + + function _get_selectable_drag(map, undo_stack) { /** Drag the selected nodes and text labels. */ @@ -405,7 +436,10 @@ define(["utils", "build"], function(utils, build) { node_ids_to_drag.forEach(function(node_id) { // update data var node = map.nodes[node_id], - updated = build.move_node_and_dependents(node, node_id, map.reactions, displacement); + updated = build.move_node_and_dependents(node, node_id, + map.reactions, + map.beziers, + displacement); reaction_ids = utils.unique_concat([reaction_ids, updated.reaction_ids]); // remember the displacements // if (!(node_id in total_displacement)) total_displacement[node_id] = { x: 0, y: 0 }; @@ -490,6 +524,7 @@ define(["utils", "build"], function(utils, build) { saved_node_ids.forEach(function(node_id) { var node = map.nodes[node_id]; build.move_node_and_dependents(node, node_id, map.reactions, + map.beziers, utils.c_times_scalar(saved_displacement, -1)); }); saved_text_label_ids.forEach(function(text_label_id) { @@ -504,6 +539,7 @@ define(["utils", "build"], function(utils, build) { saved_node_ids.forEach(function(node_id) { var node = map.nodes[node_id]; build.move_node_and_dependents(node, node_id, map.reactions, + map.beziers, saved_displacement); }); saved_text_label_ids.forEach(function(text_label_id) { @@ -558,33 +594,42 @@ define(["utils", "build"], function(utils, build) { return updated_segment_objs; } } - function get_bezier_drag(map) { - var move_bezier = function(reaction_id, segment_id, bezier, displacement) { + function _get_bezier_drag(map) { + var move_bezier = function(reaction_id, segment_id, bez, bezier_id, displacement) { var segment = map.reactions[reaction_id].segments[segment_id]; - segment['b'+bezier] = utils.c_plus_c(segment['b'+bezier], displacement); + segment[bez] = utils.c_plus_c(segment[bez], displacement); + map.beziers[bezier_id].x = segment[bez].x; + map.beziers[bezier_id].y = segment[bez].y; }, start_fn = function(d) { + d.dragging = true; }, drag_fn = function(d, displacement, total_displacement) { // draw - move_bezier(d.reaction_id, d.segment_id, d.bezier, displacement); - map.draw_these_reactions([d.reaction_id]); + move_bezier(d.reaction_id, d.segment_id, d.bezier, d.bezier_id, + displacement); + map.draw_these_reactions([d.reaction_id], false); + map.draw_these_beziers([d.bezier_id]); }, end_fn = function(d) { + d.dragging = false; }, undo_fn = function(d, displacement) { - move_bezier(d.reaction_id, d.segment_id, d.bezier, + move_bezier(d.reaction_id, d.segment_id, d.bezier, d.bezier_id, utils.c_times_scalar(displacement, -1)); - map.draw_these_reactions([d.reaction_id]); + map.draw_these_reactions([d.reaction_id], false); + map.draw_these_beziers([d.bezier_id]); }, redo_fn = function(d, displacement) { - move_bezier(d.reaction_id, d.segment_id, d.bezier, displacement); - map.draw_these_reactions([d.reaction_id]); + move_bezier(d.reaction_id, d.segment_id, d.bezier, d.bezier_id, + displacement); + map.draw_these_reactions([d.reaction_id], false); + map.draw_these_beziers([d.bezier_id]); }; - return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, - redo_fn, this.map.sel); + return this._get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, + redo_fn, this.map.sel); } - function get_reaction_label_drag(map) { + function _get_reaction_label_drag(map) { var move_label = function(reaction_id, displacement) { var reaction = map.reactions[reaction_id]; reaction.label_x = reaction.label_x + displacement.x; @@ -607,10 +652,10 @@ define(["utils", "build"], function(utils, build) { move_label(d.reaction_id, displacement); map.draw_these_reactions([d.reaction_id]); }; - return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, - redo_fn, this.map.sel); + return this._get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, + redo_fn, this.map.sel); } - function get_node_label_drag(map) { + function _get_node_label_drag(map) { var move_label = function(node_id, displacement) { var node = map.nodes[node_id]; node.label_x = node.label_x + displacement.x; @@ -633,11 +678,11 @@ define(["utils", "build"], function(utils, build) { move_label(d.node_id, displacement); map.draw_these_nodes([d.node_id]); }; - return this.get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, - redo_fn, this.map.sel); + return this._get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, + redo_fn, this.map.sel); } - function get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, relative_to_selection) { + function _get_generic_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, relative_to_selection) { /** Make a generic drag behavior, with undo/redo. start_fn: function(d) Called at dragstart. @@ -698,10 +743,10 @@ define(["utils", "build"], function(utils, build) { return behavior; } - function get_generic_angular_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, - get_center, relative_to_selection) { + function _get_generic_angular_drag(start_fn, drag_fn, end_fn, undo_fn, redo_fn, + get_center, relative_to_selection) { /** Make a generic drag behavior, with undo/redo. Supplies angles in - place of displacements. + place of displacements. start_fn: function(d) Called at dragstart. diff --git a/escher/js/src/Builder.js b/escher/js/src/Builder.js index 5b3765ba..c6f9d53c 100644 --- a/escher/js/src/Builder.js +++ b/escher/js/src/Builder.js @@ -283,6 +283,7 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C this.map.behavior.toggle_selectable_drag(mode=='brush' || mode=='rotate'); this.map.behavior.toggle_label_drag(mode=='brush'); this.map.behavior.toggle_text_label_edit(mode=='text'); + this.map.behavior.toggle_bezier_drag(mode=='brush'); // edit selections if (mode=='view' || mode=='text') this.map.select_none(); diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index d3f0d7f2..4f9036a2 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -297,7 +297,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } // populate the beziers - map.beziers = build.beziers_for_reactions(map.reactions); + map.beziers = build.new_beziers_for_reactions(map.reactions); // get largest ids for adding new reactions, nodes, text labels, and // segments @@ -500,26 +500,38 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan /** Draw the all reactions, nodes, & text labels. */ - this.draw_all_reactions(); + this.draw_all_reactions(true); // also draw beziers this.draw_all_nodes(); this.draw_all_text_labels(); } - function draw_all_reactions() { + function draw_all_reactions(draw_beziers) { /** Draw all reactions, and clear deleted reactions. + Arguments + --------- + + draw_beziers: (Boolean, default True) Whether to also draw the bezier + control points. + */ + if (draw_beziers===undefined) draw_beziers = true; + // Draw all reactions. var reaction_ids = []; for (var reaction_id in this.reactions) { reaction_ids.push(reaction_id); } - this.draw_these_reactions(reaction_ids); + // If draw_beziers is true, just draw them all, rather than deciding + // which ones to draw. + this.draw_these_reactions(reaction_ids, false); + if (draw_beziers) + this.draw_all_beziers(); // Clear all deleted reactions. - this.clear_deleted_reactions(); + this.clear_deleted_reactions(draw_beziers); } - function draw_these_reactions(reaction_ids) { + function draw_these_reactions(reaction_ids, draw_beziers) { /** Draw specific reactions. Does nothing with exit selection. Use clear_deleted_reactions to remove @@ -530,7 +542,12 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan reactions_ids: An array of reaction_ids to update. + draw_beziers: (Boolean, default True) Whether to also draw the bezier + control points. + */ + if (draw_beziers===undefined) draw_beziers = true; + // find reactions for reaction_ids var reaction_subset = utils.object_slice_for_ids(this.reactions, reaction_ids); @@ -549,17 +566,44 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // draw the reactions utils.draw_an_object(this.sel, '#reactions', '.reaction', reaction_subset, - 'reaction_id', draw.create_reaction, update_fn); + 'reaction_id', draw.create_reaction, update_fn); + + if (draw_beziers) { + // particular beziers to draw + var bezier_ids = build.bezier_ids_for_reaction_ids(reaction_subset); + this.draw_these_beziers(bezier_ids); + } } - function clear_deleted_reactions() { + function clear_deleted_reactions(draw_beziers) { /** Remove any reactions that are not in *this.reactions*. + Arguments + --------- + + draw_beziers: (Boolean, default True) Whether to also clear deleted + bezier control points. + */ - // remove deleted - utils.draw_an_object(this.sel, '#reactions', '.reaction', this.reactions, - 'reaction_id', null, null, + if (draw_beziers===undefined) draw_beziers = true; + + // remove deleted reactions and segments + utils.draw_an_object(this.sel, '#reactions', '.reaction', this.reactions, 'reaction_id', + null, + clear_deleted_segments, function(sel) { sel.remove(); }); + + if (draw_beziers==true) + this.clear_deleted_beziers(); + + // definitions + function clear_deleted_segments(update_selection) { + // draw segments + utils.draw_a_nested_object(update_selection, '.segment-group', 'segments', 'segment_id', + null, + null, + function(sel) { sel.remove(); }); + }; } function draw_all_nodes() { @@ -705,9 +749,12 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // function to update beziers var update_fn = function(sel) { return draw.update_bezier(sel, - this.beziers_enabled, + this.beziers_enabled, this.behavior.bezier_drag, - this.nodes); + this.behavior.bezier_mouseover, + this.behavior.bezier_mouseout, + this.nodes, + this.reactions); }.bind(this); // draw the beziers @@ -1080,9 +1127,15 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan should_draw: A boolean argument to determine whether to draw the changes to the map. */ + + // 8/29/14 + // ALSO, move beziers (dependents) on rotate + // ALSO, L1466 + // ALSO, single node click is broken + var out = this.segments_and_reactions_for_nodes(selected_nodes), - reactions = out.reactions, - segment_objs_w_segments = out.segment_objs_w_segments; + segment_objs_w_segments = out.segment_objs_w_segments, // TODO repeated values here + reactions = out.reactions; // copy nodes to undelete var saved_nodes = utils.clone(selected_nodes), @@ -1093,8 +1146,8 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan selected_text_labels) { // delete nodes, segments, and reactions with no segments this.delete_node_data(Object.keys(selected_nodes)); - this.delete_segment_data(segment_objs); - this.delete_reaction_data(Object.keys(reactions)); + this.delete_segment_data(segment_objs); // also deletes beziers + this.delete_reaction_data(Object.keys(reactions)); this.delete_text_label_data(Object.keys(selected_text_labels)); // apply the reaction and node data @@ -1104,16 +1157,16 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.apply_metabolite_data_domain(); // redraw - // TODO just redraw these nodes, segments, and labels if (should_draw) { - this.clear_deleted_reactions(); + this.clear_deleted_reactions(); // also clears segments and beziers this.clear_deleted_nodes(); this.clear_deleted_text_labels(); } }.bind(this); // delete - delete_and_draw(selected_nodes, reactions, segment_objs_w_segments, selected_text_labels); + delete_and_draw(selected_nodes, reactions, segment_objs_w_segments, + selected_text_labels); // add to undo/redo stack this.undo_stack.push(function() { @@ -1123,7 +1176,9 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.extend_nodes(saved_nodes); this.extend_reactions(saved_reactions); var reaction_ids_to_draw = Object.keys(saved_reactions); - saved_segment_objs_w_segments.forEach(function(segment_obj) { + for (var segment_id in saved_segment_objs_w_segments) { + var segment_obj = saved_segment_objs_w_segments[segment_id]; + var segment = segment_obj.segment; this.reactions[segment_obj.reaction_id] .segments[segment_obj.segment_id] = segment; @@ -1137,9 +1192,16 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan segment_id: segment_obj.segment_id }); }.bind(this)); + // extend the beziers + var seg_id = segment_obj.segment_id, + r_id = segment_obj.reaction_id, + seg_o = {}; + seg_o[seg_id] = segment_obj.segment; + utils.extend(this.beziers, build.new_beziers_for_segments(seg_o, r_id)); + if (reaction_ids_to_draw.indexOf(segment_obj.reaction_id)==-1) reaction_ids_to_draw.push(segment_obj.reaction_id); - }.bind(this)); + } // apply the reaction and node data // if the scale changes, redraw everything @@ -1192,13 +1254,14 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } function delete_segment_data(segment_objs) { - /** Delete segments, and update connected_segments in nodes. Also - deletes any reactions with 0 segments. + /** Delete segments, update connected_segments in nodes, and delete + bezier points. Also deletes any reactions with 0 segments. - segment_objs: Array of objects with { reaction_id: "123", segment_id: "456" } + segment_objs: Object with values like { reaction_id: "123", segment_id: "456" } */ - segment_objs.forEach(function(segment_obj) { + for (var segment_id in segment_objs) { + var segment_obj = segment_objs[segment_id]; var reaction = this.reactions[segment_obj.reaction_id]; // segment already deleted @@ -1214,8 +1277,14 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan }); }.bind(this)); + // remove beziers + ['b1', 'b2'].forEach(function(bez) { + var bez_id = build.bezier_id_for_segment_id(segment_obj.segment_id, bez); + delete this.beziers[bez_id]; + }.bind(this)); + delete reaction.segments[segment_obj.segment_id]; - }.bind(this)); + } } function delete_reaction_data(reaction_ids) { /** Delete reactions and remove from search index. @@ -1405,7 +1474,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.cobra_model.cofactors, direction), new_nodes = out.new_nodes, - new_reactions = out.new_reactions; + new_reactions = out.new_reactions; //TODO draw new beziers // draw extend_and_draw_reaction.apply(this, [new_nodes, new_reactions, selected_node_id]); @@ -1598,8 +1667,9 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan function segments_and_reactions_for_nodes(nodes) { /** Get segments and reactions that should be deleted with node deletions + */ - var segment_objs_w_segments = [], + var segment_objs_w_segments = {}, these_reactions = {}, segment_ids_for_reactions = {}, reactions = this.reactions; @@ -1612,7 +1682,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan segment = reaction.segments[segment_obj.segment_id], segment_obj_w_segment = utils.clone(segment_obj); segment_obj_w_segment['segment'] = utils.clone(segment); - segment_objs_w_segments.push(segment_obj_w_segment); + segment_objs_w_segments[segment_obj.segment_id] = segment_obj_w_segment; if (!(segment_obj.reaction_id in segment_ids_for_reactions)) segment_ids_for_reactions[segment_obj.reaction_id] = []; segment_ids_for_reactions[segment_obj.reaction_id].push(segment_obj.segment_id); diff --git a/escher/js/src/build.js b/escher/js/src/build.js index ab35247c..ef761596 100644 --- a/escher/js/src/build.js +++ b/escher/js/src/build.js @@ -3,7 +3,10 @@ define(["utils"], function(utils) { rotate_nodes: rotate_nodes, move_node_and_dependents: move_node_and_dependents, new_text_label: new_text_label, - beziers_for_reactions: beziers_for_reactions }; + bezier_id_for_segment_id: bezier_id_for_segment_id, + bezier_ids_for_reaction_ids: bezier_ids_for_reaction_ids, + new_beziers_for_segments: new_beziers_for_segments, + new_beziers_for_reactions: new_beziers_for_reactions }; // definitions function new_reaction(bigg_id, cobra_reaction, cobra_metabolites, @@ -235,7 +238,7 @@ define(["utils"], function(utils) { angle, selected_node_coords); // new_beziers object - var new_beziers = beziers_for_reactions(new_reactions); + var new_beziers = new_beziers_for_reactions(new_reactions); return { new_reactions: new_reactions, new_beziers: new_beziers, @@ -294,7 +297,7 @@ define(["utils"], function(utils) { reaction_ids: updated_reaction_ids }; } - function move_node_and_dependents(node, node_id, reactions, displacement) { + function move_node_and_dependents(node, node_id, reactions, beziers, displacement) { /** Move the node and its labels and beziers. */ @@ -307,13 +310,19 @@ define(["utils"], function(utils) { if (reaction === undefined) return; // update beziers - var segment = reaction.segments[segment_obj.segment_id]; - if (segment.from_node_id==node_id && segment.b1) { - segment.b1 = utils.c_plus_c(segment.b1, displacement); - } - if (segment.to_node_id==node_id && segment.b2) { - segment.b2 = utils.c_plus_c(segment.b2, displacement); - } + var segment_id = segment_obj.segment_id, + segment = reaction.segments[segment_id]; + [['b1', 'from_node_id'], ['b2', 'to_node_id']].forEach(function(c) { + var bez = c[0], + node = c[1]; + if (segment[node]==node_id && segment[bez]) { + segment[bez] = utils.c_plus_c(segment[bez], displacement); + var tbez = beziers[bezier_id_for_segment_id(segment_id, bez)]; + tbez.x = segment[bez].x; + tbez.y = segment[bez].y; + } + }); + // add to list of updated reaction ids if it isn't already there if (updated.reaction_ids.indexOf(segment_obj.reaction_id) < 0) { updated.reaction_ids.push(segment_obj.reaction_id); @@ -437,42 +446,85 @@ define(["utils"], function(utils) { return {id: new_id, label: new_label}; } - function beziers_for_reactions(reactions) { - throw Error('Not Implemented'); + function bezier_id_for_segment_id(segment_id, bez) { + return segment_id+'_'+bez; + } + + function bezier_ids_for_reaction_ids(reactions) { + /** Return an array of beziers ids for the array of reaction ids. + + Arguments + --------- + + reactions: A reactions object, e.g. a subset of *escher.Map.reactions*. + + */ + var bezier_ids = []; + for (var reaction_id in reactions) { + var reaction = reactions[reaction_id]; + + for (var segment_id in reaction.segments) { + var segment = reaction.segments[segment_id]; + + ['b1', 'b2'].forEach(function(bez) { + var seg_bez = segment[bez]; + if (seg_bez !== null) { + bezier_ids.push(bezier_id_for_segment_id(segment_id, bez)); + } + }); + } + } + return bezier_ids; + } + + function new_beziers_for_segments(segments, reaction_id) { + /** Return an object containing beziers for the segments object. + Arguments + --------- + + segments: A segments object, e.g. *escher.Map.segments*. + + reaction_id: The reaction id for the segments. + + */ var beziers = {}; + for (var segment_id in segments) { + var segment = segments[segment_id]; + + ['b1', 'b2'].forEach(function(bez) { + var seg_bez = segment[bez]; + if (seg_bez !== null) { + var bezier_id = bezier_id_for_segment_id(segment_id, bez); + beziers[bezier_id] = { + bezier: bez, + x: seg_bez.x, + y: seg_bez.y, + reaction_id: reaction_id, + segment_id: segment_id + }; + } + }); + } return beziers; + } - // new bezier points - // var bez = update_selection.select('.beziers') - // .selectAll('.bezier-group') - // .data(function(d) { - // var beziers = [], - // reaction_id = this.parentNode.parentNode.parentNode.__data__.reaction_id, - // segment_id = this.parentNode.parentNode.__data__.segment_id; - // //TODO fix; this is a bit of a hack - // if (d.b1!=null && d.b1.x!=null && d.b1.y!=null) - // beziers.push({bezier: 1, - // x: d.b1.x, - // y: d.b1.y, - // reaction_id: reaction_id, - // segment_id: segment_id }); - // if (d.b2!=null && d.b2.x!=null && d.b2.y!=null) - // beziers.push({bezier: 2, - // x: d.b2.x, - // y: d.b2.y, - // reaction_id: reaction_id, - // segment_id: segment_id }); - // return beziers; - // }, function(d) { return d.bezier; }); - // bez.enter().call(function(sel) { - // return create_bezier(sel); - // }); - // // update bezier points - // bez.call(function(sel) { - // return update_bezier(sel, show_beziers, bezier_drag_behavior, drawn_nodes); - // }); - // // remove - // bez.exit().remove(); + function new_beziers_for_reactions(reactions) { + /** Return an object containing beziers for the reactions object. + + Arguments + --------- + + reactions: A reactions object, e.g. *escher.Map.reactions*. + + */ + var beziers = {}; + for (var reaction_id in reactions) { + var reaction = reactions[reaction_id]; + + var these = new_beziers_for_segments(reaction.segments, reaction_id); + utils.extend(beziers, these); + } + return beziers; } }); diff --git a/escher/js/src/draw.js b/escher/js/src/draw.js index 147bca2d..6f3e8b2b 100644 --- a/escher/js/src/draw.js +++ b/escher/js/src/draw.js @@ -63,26 +63,17 @@ define(['utils', 'data_styles'], function(utils, data_styles) { reaction_data_styles, label_drag_behavior); }); - // select segments - var sel = update_selection - .selectAll('.segment-group') - .data(function(d) { - return utils.make_array(d.segments, 'segment_id'); - }, function(d) { return d.segment_id; }); - - // new segments - sel.enter().call(create_segment); - - // update segments - sel.call(function(sel) { - return update_segment(sel, scale, drawn_nodes, defs, - default_reaction_color, - has_reaction_data, reaction_data_styles); - }); - - // old segments - sel.exit().remove(); - + // draw segments + utils.draw_a_nested_object(update_selection, '.segment-group', 'segments', 'segment_id', + create_segment, + function(sel) { + return update_segment(sel, scale, drawn_nodes, defs, + default_reaction_color, + has_reaction_data, reaction_data_styles); + }, + function(sel) { + sel.remove(); + }); // new connect lines // var lines = sel @@ -329,83 +320,54 @@ define(['utils', 'data_styles'], function(utils, data_styles) { utils.check_undefined(arguments, ['enter_selection']); var g = enter_selection.append('g') + .attr('id', function(d) { return d.bezier_id; }) .attr('class', function(d) { return 'bezier'; }); + g.append('path') + .attr('class', 'connect-line'); g.append('circle') - .attr('class', function(d) { return 'bezier-circle bezier'+d.bezier; }) + .attr('class', function(d) { return 'bezier-circle '+d.bezier; }) .style('stroke-width', String(1)+'px') - .attr('r', String(7)+'px') - .on('mouseover', function(d) { - d3.select(this).style('stroke-width', String(3)+'px'); - d3.select(this.parentNode.parentNode) - .selectAll('.connect-line') - .attr('visibility', 'visible'); - }) - .on('mouseout', function(d) { - d3.select(this).style('stroke-width', String(1)+'px'); - d3.select(this.parentNode.parentNode) - .selectAll('.connect-line') - .attr('visibility', 'hidden'); - }); + .attr('r', String(7)+'px'); } function update_bezier(update_selection, show_beziers, drag_behavior, - drawn_nodes) { + mouseover, mouseout, drawn_nodes, drawn_reactions) { utils.check_undefined(arguments, ['update_selection', 'show_beziers', - 'drag_behavior', 'drawn_nodes']); - - update_selection - .call(turn_off_drag) - .call(drag_behavior); + 'drag_behavior', 'mouseover', 'mouseout', + 'drawn_nodes', 'drawn_reactions']); + if (!show_beziers) { update_selection.attr('visibility', 'hidden'); return; - } + } else { + update_selection.attr('visibility', 'visible'); + } // draw bezier points update_selection - .attr('visibility', 'visible') + .select('.bezier-circle') + .call(turn_off_drag) + .call(drag_behavior) + .on('mouseover', mouseover) + .on('mouseout', mouseout) .attr('transform', function(d) { if (d.x==null || d.y==null) return ''; return 'translate('+d.x+','+d.y+')'; }); - // new bezier lines - var bez_lines = update_selection - .selectAll('.connect-line') - .data(function(d) { - var bezier_line, node, - segment_d = this.parentNode.parentNode.parentNode.__data__; - node = (d.bezier==1 ? - drawn_nodes[segment_d.from_node_id] : - drawn_nodes[segment_d.to_node_id]); - bezier_line = { x: d.x, - y: d.y, - source_x: node.x, - source_y: node.y}; - return [bezier_line]; - }); - bez_lines.enter().call(function(sel) { - return create_bezier_line(sel); - }); - // update bezier lines - bez_lines.call(function(sel) { return update_bezier_line(sel); }); - // remove - bez_lines.exit().remove(); - - // definitions - function create_bezier_line(enter_selection) { - enter_selection.append('path') - .attr('class', function(d) { return 'connect-line'; }) - .attr('visibility', 'hidden'); - } - function update_bezier_line(update_selection) { - update_selection - .attr('d', function(d) { - if (d.x==null || d.y==null || d.source_x==null || d.source_y==null) - return ''; - return 'M0, 0 '+(d.source_x-d.x)+','+(d.source_y-d.y); - }); - } + // update bezier line + update_selection + .select('.connect-line') + .attr('d', function(d) { + var node, + segment_d = drawn_reactions[d.reaction_id].segments[d.segment_id]; + node = (d.bezier=='b1' ? + drawn_nodes[segment_d.from_node_id] : + drawn_nodes[segment_d.to_node_id]); + if (d.x==null || d.y==null || node.x==null || node.y==null) + return ''; + return 'M'+d.x+', '+d.y+' '+(node.x)+','+(node.y); + }); } function create_node(enter_selection, drawn_nodes, drawn_reactions) { diff --git a/escher/js/src/utils.js b/escher/js/src/utils.js index b3255853..64d874f0 100644 --- a/escher/js/src/utils.js +++ b/escher/js/src/utils.js @@ -8,6 +8,7 @@ define(["lib/vkbeautify"], function(vkbeautify) { make_class: make_class, setup_defs: setup_defs, draw_an_object: draw_an_object, + draw_a_nested_object: draw_a_nested_object, make_array: make_array, compare_arrays: compare_arrays, array_to_object: array_to_object, @@ -177,6 +178,27 @@ define(["lib/vkbeautify"], function(vkbeautify) { exit_function) { /** Run through the d3 data binding steps for an object. + Arguments + --------- + + container_sel: A d3 selection containing all objects. + + parent_node_selector: A selector string for a subselection of + container_sel. + + children_selector: A selector string for each DOM element to bind. + + object: An object to bind to the selection. + + id_key: The key that will be used to store object IDs in the bound data + points. + + create_function: A function for enter selection. + + update_function: A function for update selection. + + exit_function: A function for exit selection. + */ var sel = container_sel.select(parent_node_selector) .selectAll(children_selector) @@ -192,6 +214,47 @@ define(["lib/vkbeautify"], function(vkbeautify) { sel.exit().call(exit_function); } + function draw_a_nested_object(container_sel, children_selector, object_data_key, + id_key, create_function, update_function, + exit_function) { + /** Run through the d3 data binding steps for an object that is nested + within another element with d3 data. + + Arguments + --------- + + container_sel: A d3 selection containing all objects. + + children_selector: A selector string for each DOM element to bind. + + object_data_key: A key for the parent object containing data for the + new selection. + + id_key: The key that will be used to store object IDs in the bound data + points. + + create_function: A function for enter selection. + + update_function: A function for update selection. + + exit_function: A function for exit selection. + + */ + var sel = container_sel.selectAll(children_selector) + .data(function(d) { + return make_array(d[object_data_key], id_key); + }, function(d) { return d[id_key]; }); + // enter: generate and place reaction + if (create_function) + sel.enter().call(create_function); + // update: update when necessary + if (update_function) + sel.call(update_function); + // exit + if (exit_function) + sel.exit().call(exit_function); + } + function make_array(obj, id_key) { // is this super slow? var array = []; for (var key in obj) { From dab0a7046b5e1e526a75d5330fb51cffb1f948e8 Mon Sep 17 00:00:00 2001 From: Zak King Date: Fri, 5 Sep 2014 15:53:01 -0700 Subject: [PATCH 11/33] Move beziers with rotation; add beziers with new reacitons. --- escher/js/src/Behavior.js | 11 +++++++---- escher/js/src/Map.js | 39 ++++++++++++++++++++++++++++----------- escher/js/src/build.js | 26 +++++++++++++++++--------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/escher/js/src/Behavior.js b/escher/js/src/Behavior.js index e22bc0ca..d78906f3 100644 --- a/escher/js/src/Behavior.js +++ b/escher/js/src/Behavior.js @@ -115,7 +115,8 @@ define(["utils", "build"], function(utils, build) { var map = this.map, selected_node_ids = Object.keys(selected_nodes), reactions = this.map.reactions, - nodes = this.map.nodes; + nodes = this.map.nodes, + beziers = this.map.beziers; var start_fn = function(d) { // silence other listeners @@ -123,7 +124,7 @@ define(["utils", "build"], function(utils, build) { }, drag_fn = function(d, angle, total_angle, center) { var updated = build.rotate_nodes(selected_nodes, reactions, - angle, center); + beziers, angle, center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); }, @@ -135,7 +136,8 @@ define(["utils", "build"], function(utils, build) { these_nodes[id] = nodes[id]; }); var updated = build.rotate_nodes(these_nodes, reactions, - -total_angle, center); + beziers, -total_angle, + center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); }, @@ -146,7 +148,8 @@ define(["utils", "build"], function(utils, build) { these_nodes[id] = nodes[id]; }); var updated = build.rotate_nodes(these_nodes, reactions, - total_angle, center); + beziers, total_angle, + center); map.draw_these_nodes(updated.node_ids); map.draw_these_reactions(updated.reaction_ids); }, diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index 4f9036a2..b25876da 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -1129,8 +1129,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan */ // 8/29/14 - // ALSO, move beziers (dependents) on rotate - // ALSO, L1466 + // TODO, L1466 // ALSO, single node click is broken var out = this.segments_and_reactions_for_nodes(selected_nodes), @@ -1255,7 +1254,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan function delete_segment_data(segment_objs) { /** Delete segments, update connected_segments in nodes, and delete - bezier points. Also deletes any reactions with 0 segments. + bezier points. segment_objs: Object with values like { reaction_id: "123", segment_id: "456" } @@ -1287,11 +1286,22 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } } function delete_reaction_data(reaction_ids) { - /** Delete reactions and remove from search index. + /** Delete reactions, segments, and beziers, and remove reaction from + search index. */ reaction_ids.forEach(function(reaction_id) { + // remove beziers + var reaction = this.reactions[reaction_id]; + for (var segment_id in reaction.segments) { + ['b1', 'b2'].forEach(function(bez) { + var bez_id = build.bezier_id_for_segment_id(segment_id, bez); + delete this.beziers[bez_id]; + }.bind(this)); + } + // delete reaction delete this.reactions[reaction_id]; + // remove from search index var found = this.search_index.remove('r'+reaction_id); if (!found) console.warn('Could not find deleted reaction in search index'); @@ -1474,14 +1484,17 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.cobra_model.cofactors, direction), new_nodes = out.new_nodes, - new_reactions = out.new_reactions; //TODO draw new beziers + new_reactions = out.new_reactions, + new_beziers = out.new_beziers; // draw - extend_and_draw_reaction.apply(this, [new_nodes, new_reactions, selected_node_id]); + extend_and_draw_reaction.apply(this, [new_nodes, new_reactions, + new_beziers, selected_node_id]); // clone the nodes and reactions, to redo this action later var saved_nodes = utils.clone(new_nodes), - saved_reactions = utils.clone(new_reactions); + saved_reactions = utils.clone(new_reactions), + saved_beziers = utils.clone(new_beziers); // add to undo/redo stack this.undo_stack.push(function() { @@ -1489,23 +1502,27 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // get the nodes to delete delete new_nodes[selected_node_id]; this.delete_node_data(Object.keys(new_nodes)); - this.delete_reaction_data(Object.keys(new_reactions)); + this.delete_reaction_data(Object.keys(new_reactions)); // also deletes beziers select_metabolite_with_id.apply(this, [selected_node_id]); // save the nodes and reactions again, for redo new_nodes = utils.clone(saved_nodes); new_reactions = utils.clone(saved_reactions); + new_beziers = utils.clone(saved_beziers); // draw this.clear_deleted_nodes(); - this.clear_deleted_reactions(); + this.clear_deleted_reactions(true); // also clears segments and beziers }.bind(this), function () { // redo // clone the nodes and reactions, to redo this action later - extend_and_draw_reaction.apply(this, [new_nodes, new_reactions, selected_node_id]); + extend_and_draw_reaction.apply(this, [new_nodes, new_reactions, + new_beziers, selected_node_id]); }.bind(this)); // definitions - function extend_and_draw_reaction(new_nodes, new_reactions, selected_node_id) { + function extend_and_draw_reaction(new_nodes, new_reactions, new_beziers, + selected_node_id) { this.extend_reactions(new_reactions); + utils.extend(this.beziers, new_beziers); // remove the selected node so it can be updated this.delete_node_data([selected_node_id]); // TODO this is a hack. fix this.extend_nodes(new_nodes); diff --git a/escher/js/src/build.js b/escher/js/src/build.js index ef761596..c31f6a2e 100644 --- a/escher/js/src/build.js +++ b/escher/js/src/build.js @@ -232,24 +232,25 @@ define(["utils"], function(utils) { var new_reactions = {}; new_reactions[new_reaction_id] = new_reaction; - // add the selected node for rotation, and return it as a new (updated) node - new_nodes[selected_node_id] = selected_node; - var updated = rotate_nodes(new_nodes, new_reactions, - angle, selected_node_coords); - // new_beziers object var new_beziers = new_beziers_for_reactions(new_reactions); + // add the selected node for rotation, and return it as a new (updated) node + new_nodes[selected_node_id] = selected_node; + rotate_nodes(new_nodes, new_reactions, new_beziers, + angle, selected_node_coords); + return { new_reactions: new_reactions, new_beziers: new_beziers, new_nodes: new_nodes }; } - function rotate_nodes(selected_nodes, reactions, angle, center) { + function rotate_nodes(selected_nodes, reactions, beziers, angle, center) { /** Rotate the nodes around center. selected_nodes: Nodes to rotate. reactions: Only updates beziers for these reactions. + beziers: Also update the bezier points. angle: Angle to rotate in radians. center: Point to rotate around. @@ -278,13 +279,20 @@ define(["utils"], function(utils) { if (reaction === undefined) return; // rotate the beziers - var segment = reaction.segments[segment_obj.segment_id]; + var segment_id = segment_obj.segment_id, + segment = reaction.segments[segment_id]; if (segment.to_node_id==node_id && segment.b2) { - var displacement = rotate_around(segment.b2); + var displacement = rotate_around(segment.b2), + bez_id = bezier_id_for_segment_id(segment_id, 'b2'); segment.b2 = utils.c_plus_c(segment.b2, displacement); + beziers[bez_id].x = segment.b2.x; + beziers[bez_id].y = segment.b2.y; } else if (segment.from_node_id==node_id && segment.b1) { - var displacement = rotate_around(segment.b1); + var displacement = rotate_around(segment.b1), + bez_id = bezier_id_for_segment_id(segment_id, 'b1'); segment.b1 = utils.c_plus_c(segment.b1, displacement); + beziers[bez_id].x = segment.b1.x; + beziers[bez_id].y = segment.b1.y; } }); From ddeb551c84d2504e5ff4c8f494f2022dd0a86990 Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sat, 6 Sep 2014 13:32:19 -0700 Subject: [PATCH 12/33] Better offline homepage. Fixed single node selection. --- escher/css/index.css | 37 +- escher/js/src/Map.js | 29 +- escher/lib/escher.1.0.0b3.js | 1209 +++++++++++++++++++----------- escher/lib/escher.1.0.0b3.min.js | 2 +- escher/templates/index.html | 29 +- spec/javascripts/BuilderSpec.js | 1 - 6 files changed, 809 insertions(+), 498 deletions(-) diff --git a/escher/css/index.css b/escher/css/index.css index 3b6b1202..3b13d535 100644 --- a/escher/css/index.css +++ b/escher/css/index.css @@ -52,17 +52,26 @@ footer a, a:hover, a:focus, a:visited { width: 100%; margin-top: 35px; } +#title-box { + display: inline-block; +} #title { color: #291E1E; font-size: 160px; - font-family: tulpen-one, serif; + font-family: tulpen-one, Futura, serif; font-weight: 400; - /* font-style: italic; */ - text-align: center; } #logo { - display: none; - width: 250px; + vertical-align: inherit; +} +@media (max-width: 768px) { + #title-box { + width: 100%; + text-align: center; + } + #logo { + display: none; + } } @media (min-width: 768px) { /*@screen-sm-min) { */ .column-button { @@ -71,16 +80,22 @@ footer a, a:hover, a:focus, a:visited { header { margin-bottom: 50px; } + #title-box { + max-width: 400px; + overflow: hidden; + } #title { + position: relative; + top: 45px; font-size: 230px; text-align: left; - display: inline; - top: 100px; - position: relative; } #logo { - position: relative; - left: -20px; - display: inline; + width: 250px; + display: inline-block; + overflow: hidden; + } + #faq { + margin-top: 50px; } } \ No newline at end of file diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index b25876da..7e85271f 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -1,4 +1,4 @@ -define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackManager", "KeyManager", "Canvas", "data_styles", "SearchIndex", "lib/bacon"], function(utils, draw, Behavior, Scale, build, UndoStack, CallbackManager, KeyManager, Canvas, data_styles, SearchIndex, bacon) { +define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackManager', 'KeyManager', 'Canvas', 'data_styles', 'SearchIndex', 'lib/bacon'], function(utils, draw, Behavior, Scale, build, UndoStack, CallbackManager, KeyManager, Canvas, data_styles, SearchIndex, bacon) { /** Defines the metabolic map data, and manages drawing and building. Arguments @@ -1012,7 +1012,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan var node_selection = this.sel.select('#nodes').selectAll('.node'), coords, selected_node; - node_selection.classed("selected", function(d) { + node_selection.classed('selected', function(d) { var selected = String(d.node_id) == String(node_id); if (selected) { selected_node = d; @@ -1040,10 +1040,13 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } // toggle selection if (shift_key_on) { + // toggle this node d3.select(classable_node) - .classed("selected", !d3.select(classable_node).classed("selected")); + .classed('selected', !d3.select(classable_node).classed('selected')); } else { - classable_selection.classed("selected", function(p) { return d === p; }); + // unselect all other nodes, and select this one + classable_selection.classed('selected', false); + d3.select(classable_node).classed('selected', true); } // run the select_metabolite callback var selected_nodes = this.sel.select('#nodes').selectAll('.selected'), @@ -1066,7 +1069,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan var out = null, self = this, node_selection = this.sel.select('#nodes').selectAll('.selected'); - node_selection.classed("selected", function(d, i) { + node_selection.classed('selected', function(d, i) { if (i==0) { out = d; return true; @@ -1078,7 +1081,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } function deselect_nodes() { var node_selection = this.sel.select('#nodes').selectAll('.node'); - node_selection.classed("selected", false); + node_selection.classed('selected', false); } function select_text_label(sel, d) { // deselect all nodes @@ -1086,7 +1089,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // find the new selection // Ignore shift key and only allow single selection for now var text_label_selection = this.sel.select('#text-labels').selectAll('.text-label'); - text_label_selection.classed("selected", function(p) { return d === p; }); + text_label_selection.classed('selected', function(p) { return d === p; }); var selected_text_labels = this.sel.select('#text-labels').selectAll('.selected'), coords; selected_text_labels.each(function(d) { @@ -1096,7 +1099,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan } function deselect_text_labels() { var text_label_selection = this.sel.select('#text-labels').selectAll('.text-label'); - text_label_selection.classed("selected", false); + text_label_selection.classed('selected', false); } // --------------------------------------------------------------------- @@ -1128,10 +1131,6 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan */ - // 8/29/14 - // TODO, L1466 - // ALSO, single node click is broken - var out = this.segments_and_reactions_for_nodes(selected_nodes), segment_objs_w_segments = out.segment_objs_w_segments, // TODO repeated values here reactions = out.reactions; @@ -1256,7 +1255,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan /** Delete segments, update connected_segments in nodes, and delete bezier points. - segment_objs: Object with values like { reaction_id: "123", segment_id: "456" } + segment_objs: Object with values like { reaction_id: '123', segment_id: '456' } */ for (var segment_id in segment_objs) { @@ -1843,7 +1842,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan // IO function save() { - utils.download_json(this.map_for_export(), "saved_map"); + utils.download_json(this.map_for_export(), 'saved_map'); } function map_for_export() { var out = { reactions: utils.clone(this.reactions), @@ -1898,7 +1897,7 @@ define(["utils", "draw", "Behavior", "Scale", "build", "UndoStack", "CallbackMan this.canvas.mouse_node.attr('width', '0px'); this.canvas.mouse_node.attr('height', '0px'); this.canvas.mouse_node.attr('transform', null); - utils.export_svg("saved_map", this.svg, true); + utils.export_svg('saved_map', this.svg, true); this.zoom_container.go_to(window_scale, window_translate, false); this.svg.attr('width', null); this.svg.attr('height', null); diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 3bd9fb08..9f2dbada 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -793,14 +793,15 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { load_the_file: load_the_file, make_class: make_class, setup_defs: setup_defs, - draw_an_array: draw_an_array, draw_an_object: draw_an_object, + draw_a_nested_object: draw_a_nested_object, make_array: make_array, compare_arrays: compare_arrays, array_to_object: array_to_object, clone: clone, extend: extend, unique_concat: unique_concat, + object_slice_for_ids: object_slice_for_ids, c_plus_c: c_plus_c, c_minus_c: c_minus_c, c_times_scalar: c_times_scalar, @@ -958,34 +959,86 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { return defs; } - function draw_an_array(container_sel, parent_node_selector, children_selector, - array, create_function, update_function) { - /** Run through the d3 data binding steps for an array. + function draw_an_object(container_sel, parent_node_selector, children_selector, + object, id_key, create_function, update_function, + exit_function) { + /** Run through the d3 data binding steps for an object. + + Arguments + --------- + + container_sel: A d3 selection containing all objects. + + parent_node_selector: A selector string for a subselection of + container_sel. + + children_selector: A selector string for each DOM element to bind. + + object: An object to bind to the selection. + + id_key: The key that will be used to store object IDs in the bound data + points. + + create_function: A function for enter selection. + + update_function: A function for update selection. + + exit_function: A function for exit selection. + */ var sel = container_sel.select(parent_node_selector) .selectAll(children_selector) - .data(array); + .data(make_array(object, id_key), function(d) { return d[id_key]; }); // enter: generate and place reaction - sel.enter().call(create_function); + if (create_function) + sel.enter().call(create_function); // update: update when necessary - sel.call(update_function); + if (update_function) + sel.call(update_function); // exit - sel.exit().remove(); + if (exit_function) + sel.exit().call(exit_function); } - function draw_an_object(container_sel, parent_node_selector, children_selector, - object, id_key, create_function, update_function) { - /** Run through the d3 data binding steps for an object. + function draw_a_nested_object(container_sel, children_selector, object_data_key, + id_key, create_function, update_function, + exit_function) { + /** Run through the d3 data binding steps for an object that is nested + within another element with d3 data. + + Arguments + --------- + + container_sel: A d3 selection containing all objects. + + children_selector: A selector string for each DOM element to bind. + + object_data_key: A key for the parent object containing data for the + new selection. + + id_key: The key that will be used to store object IDs in the bound data + points. + + create_function: A function for enter selection. + + update_function: A function for update selection. + + exit_function: A function for exit selection. + */ - var sel = container_sel.select(parent_node_selector) - .selectAll(children_selector) - .data(make_array(object, id_key), function(d) { return d[id_key]; }); + var sel = container_sel.selectAll(children_selector) + .data(function(d) { + return make_array(d[object_data_key], id_key); + }, function(d) { return d[id_key]; }); // enter: generate and place reaction - sel.enter().call(create_function); + if (create_function) + sel.enter().call(create_function); // update: update when necessary - sel.call(update_function); + if (update_function) + sel.call(update_function); // exit - sel.exit().remove(); + if (exit_function) + sel.exit().call(exit_function); } function make_array(obj, id_key) { // is this super slow? @@ -1090,6 +1143,27 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { return new_array; } + function object_slice_for_ids(obj, ids) { + /** Return a copy of the object with just the given ids. + + Arguments + --------- + + obj: An object. + + ids: An array of id strings. + + */ + var subset = {}, i = -1; + while (++i0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function T(e,t,n){var r=function(e){return N(e,t,n)};return e.map(r)}function N(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function C(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function k(e){return e*180/Math.PI}function L(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function A(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function O(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function M(e,t){return e+"_"+t}function _(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function D(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){D(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;D(e[s],t[s],n)}}}function P(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function H(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_array:l,draw_an_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,c_plus_c:y,c_minus_c:b,c_times_scalar:w,download_json:E,load_json:S,export_svg:x,rotate_coords_recursive:T,rotate_coords:N,get_angle:C,to_degrees:k,angle_for_event:L,distance:A,check_undefined:O,compartmentalize:M,decompartmentalize:_,check_r:D,mean:P,check_for_parent_tag:H}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c,h,p){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,u,c,p)});var d=t.selectAll(".segment-group").data(function(t){return e.make_array(t.segments,"segment_id")},function(e){return e.segment_id});d.enter().call(f),d.call(function(e){return l(e,n,r,i,s,o,u,c,h)}),d.exit().remove()}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads"),n.append("g").attr("class","beziers")}function l(t,r,i,s,o,u,a,f,l){function d(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class",function(e){return"bezier-group"});n.append("circle").attr("class",function(e){return"bezier bezier"+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px").on("mouseover",function(e){d3.select(this).style("stroke-width",String(3)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","visible")}).on("mouseout",function(e){d3.select(this).style("stroke-width",String(1)+"px"),d3.select(this.parentNode.parentNode).selectAll(".connect-line").attr("visibility","hidden")})}function m(t,r,i,s){function u(e){e.append("path").attr("class",function(e){return"connect-line"}).attr("visibility","hidden")}function a(e){e.attr("d",function(e){return e.x==null||e.y==null||e.source_x==null||e.source_y==null?"":"M0, 0 "+(e.source_x-e.x)+","+(e.source_y-e.y)})}e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","drawn_nodes"]),t.call(n).call(i);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible").attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"});var o=t.selectAll(".connect-line").data(function(e){var t,n,r=this.parentNode.parentNode.parentNode.__data__;return n=e.bezier==1?s[r.from_node_id]:s[r.to_node_id],t={x:e.x,y:e.y,source_x:n.x,source_y:n.y},[t]});o.enter().call(function(e){return u(e)}),o.call(function(e){return a(e)}),o.exit().remove()}e.check_undefined(arguments,["update_selection","scale","drawn_nodes","show_beziers","defs","default_reaction_color","has_reaction_data","reaction_data_styles","bezier_drag_behavior"]);var c=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=i[e.from_node_id],n=i[e.to_node_id],r=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&r!==null){var o=c(e.reversibility,e.from_node_coefficient),u=r===null?n:r;t=v(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=c(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=v(o,u,n,"end")}var a="M"+t.x+","+t.y+" ";return r!==null&&s!==null&&(a+="C"+r.x+","+r.y+" "+s.x+","+s.y+" "),a+=n.x+","+n.y,a}).style("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}).style("stroke-width",function(e){if(a&&f.indexOf("size")!==-1){var t=e.data;return r.reaction_size(t===null?0:t)}return r.reaction_size(0)});var h=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],r=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=i[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var a=c(t.reversibility,t.from_node_coefficient),f=u===null?h:u,l=e.to_degrees(e.get_angle([o,f]))+90;o=v(a,o,f,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:l,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=i[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var a=c(t.reversibility,t.to_node_coefficient),f=p===null?o:p,l=e.to_degrees(e.get_angle([h,f]))+90;h=v(a,f,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:l,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});h.enter().append("path").classed("arrowhead",!0),h.attr("d",function(e){var t=20,n=13;if(a&&f.indexOf("size")!==-1){var i=e.data;t+=r.reaction_size(i)-r.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,n]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(a&&f.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return r.reaction_color(t===null?0:t)}return"#FFFFFF"}return u}).attr("stroke",function(e){if(a&&f.indexOf("color")!==-1){var t=e.data;return r.reaction_color(t===null?0:t)}return u}),h.exit().remove();var p=t.select(".beziers").selectAll(".bezier-group").data(function(e){var t=[],n=this.parentNode.parentNode.parentNode.__data__.reaction_id,r=this.parentNode.parentNode.__data__.segment_id;return e.b1!=null&&e.b1.x!=null&&e.b1.y!=null&&t.push({bezier:1,x:e.b1.x,y:e.b1.y,reaction_id:n,segment_id:r}),e.b2!=null&&e.b2.x!=null&&e.b2.y!=null&&t.push({bezier:2,x:e.b2.x,y:e.b2.y,reaction_id:n,segment_id:r}),t},function(e){return e.bezier});p.enter().call(function(e){return d(e)}),p.call(function(e){return m(e,s,l,i)}),p.exit().remove()}function c(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function h(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function p(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function d(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function v(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_node:c,update_node:h,create_text_label:p,update_text_label:d,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,l){l=Math.PI/180*l;var c=String(++a.reactions),h={x:u.x,y:u.y},p=300,d=[h,e.c_plus_c(h,{x:p,y:0})],v={x:(d[0].x+d[1].x)/2,y:(d[0].y+d[1].y)/2},m;Math.abs(l)e[1]?t:e},M=b.reduce(O,[0,0])[0],_=w.reduce(O,[0,0])[0];for(var T in y.metabolites){var N=y.metabolites[T];N.coefficient<0?(N.index==M&&(N.is_primary=!0),N.count=E+1):(N.index==_&&(N.is_primary=!0),N.count=S+1)}var D={},P=[{node_type:"anchor_reactants",dis:{x:g*(x?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:g*(x?-1:1),y:0}}],H={};P.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";D[t]={node_type:n,x:v.x+e.dis.x,y:v.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},H[e.node_type]=t});var B=[[H.anchor_reactants,H.center],[H.anchor_products,H.center]];B.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);y.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:y.reversibility},D[t].connected_segments.push({segment_id:r,reaction_id:c}),D[n].connected_segments.push({segment_id:r,reaction_id:c})});var j=D;for(var T in y.metabolites){var N=y.metabolites[T],F,I;N.coefficient<0?(F=M,I=H.anchor_reactants):(F=_,I=H.anchor_products);var q=s(N,F,d,v,p,x);if(u.bigg_id==N.bigg_id){var R=String(++a.segments);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:o,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},u.connected_segments.push({segment_id:R,reaction_id:c}),j[I].connected_segments.push({segment_id:R,reaction_id:c})}else{var R=String(++a.segments),U=String(++a.nodes);y.segments[R]={b1:q.b1,b2:q.b2,from_node_id:I,to_node_id:U,from_node_coefficient:null,to_node_coefficient:N.coefficient,reversibility:y.reversibility},j[U]={connected_segments:[{segment_id:R,reaction_id:c}],x:q.circle.x,y:q.circle.y,node_is_primary:Boolean(N.is_primary),label_x:q.circle.x+m.x,label_y:q.circle.y+m.y,name:N.name,bigg_id:N.bigg_id,node_type:"metabolite"},j[I].connected_segments.push({segment_id:R,reaction_id:c})}}for(var t in y.metabolites)y.metabolites[t]={coefficient:y.metabolites[t].coefficient};var z={};z[c]=y,j[o]=u;var W=n(j,z,l,h);return{new_reactions:z,new_nodes:j}}function n(t,n,r,s){var o=function(t){return t===null?null:e.rotate_coords(t,r,s)},u=[],a=[];for(var f in t){var l=t[f],c=o({x:l.x,y:l.y}),h=i(l,n,c);l.connected_segments.map(function(t){var r=n[t.reaction_id];if(r===undefined)return;var i=r.segments[t.segment_id];if(i.to_node_id==f&&i.b2){var s=o(i.b2);i.b2=e.c_plus_c(i.b2,s)}else if(i.from_node_id==f&&i.b1){var s=o(i.b1);i.b1=e.c_plus_c(i.b1,s)}}),a=e.unique_concat([a,h.reaction_ids]),u.push(f)}return{node_ids:u,reaction_ids:a}}function r(t,n,r,s){var o=i(t,r,s);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var u=i.segments[t.segment_id];u.from_node_id==n&&u.b1&&(u.b1=e.c_plus_c(u.b1,s)),u.to_node_id==n&&u.b2&&(u.b2=e.c_plus_c(u.b2,s)),o.reaction_ids.indexOf(t.reaction_id)<0&&o.reaction_ids.push(t.reaction_id)}),o}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function m(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function g(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function y(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=y(s),m.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=function(e){d3.event.sourceEvent.stopPropagation()},c=function(e,n,r,i){var u=t.rotate_nodes(s,a,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},h=function(e){},p=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(){return this.center}.bind(this);this.rotation_drag=this.get_generic_angular_drag(l,c,h,p,d,v,this.map.sel),i.call(this.rotation_drag)}else g.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this.get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this.get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this.get_reaction_label_drag(this.map),this.node_label_drag=this.get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function h(t){var n=function(n,r,i,s){var o=t.reactions[n].segments[r];o["b"+i]=e.c_plus_c(o["b"+i],s)},r=function(e){},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function p(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this.get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function m(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,get_selectable_drag:c,get_bezier_drag:h,get_reaction_label_drag:p,get_node_label_drag:d,get_generic_drag:v,get_generic_angular_drag:m},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,i,s,o,u,a,f,l){function k(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var c=t.canvas,p=new h(n,r,i,s,o,u,a,f,c,l);p.reactions=t.reactions,p.nodes=t.nodes,p.membranes=t.membranes,p.text_labels=t.text_labels,p.info=t.info;for(var d in p.reactions){var v=p.reactions[d];l&&p.search_index.insert("r"+d,{name:v.bigg_id,data:{type:"reaction",reaction_id:d}});for(var m in v.segments){var g=v.segments[m];g.reversibility=v.reversibility;var y=p.nodes[g.from_node_id].bigg_id;y in v.metabolites&&(g.from_node_coefficient=v.metabolites[y].coefficient);var b=p.nodes[g.to_node_id].bigg_id;b in v.metabolites&&(g.to_node_coefficient=v.metabolites[b].coefficient);var w=p.nodes[g.from_node_id],E=p.nodes[g.to_node_id];if(w["node_type"]=="metabolite"||E["node_type"]=="metabolite"){var S=e.c_plus_c(w,e.c_times_scalar(e.c_minus_c(E,w),.5));g.b1===null&&(g.b1=S),g.b2===null&&(g.b2=S)}}}if(l)for(var x in p.nodes){var T=p.nodes[x];if(T.node_type!="metabolite")continue;p.search_index.insert("n"+x,{name:T.bigg_id,data:{type:"metabolite",node_id:x}})}p.largest_ids.reactions=k(p.reactions),p.largest_ids.nodes=k(p.nodes),p.largest_ids.text_labels=k(p.text_labels);var N=0;for(var C in p.reactions)N=k(p.reactions[C].segments,N);return p.largest_ids.segments=N,p.apply_reaction_data_to_map(),p.apply_metabolite_data_to_map(),p}function v(e){e.append("g").attr("id","nodes"),e.append("g").attr("id","reactions"),e.append("g").attr("id","text-labels"),e.append("g").attr("id","membranes")}function m(){this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove(),this.sel.select("#membranes").selectAll(".membrane").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){var n=this.sel,r=this.membranes,i=this.scale,s=this.reactions,o=this.nodes,u=this.text_labels,a=this.defs,f=this.default_reaction_color,l=this.behavior.bezier_drag,c=this.behavior.selectable_click,h=this.behavior.node_mouseover,p=this.behavior.node_mouseout,d=this.behavior.selectable_drag,v=this.behavior.reaction_label_drag,m=this.behavior.node_label_drag,g=this.behavior.text_label_click,y=this.behavior.selectable_drag,b=this.has_reaction_data(),w=this.settings.data_styles.reaction,E=this.has_metabolite_data(),S=this.settings.data_styles.metabolite,x=this.beziers_enabled;e.draw_an_array(n,"#membranes",".membrane",r,t.create_membrane,t.update_membrane),e.draw_an_object(n,"#reactions",".reaction",s,"reaction_id",t.create_reaction,function(e){return t.update_reaction(e,i,o,x,a,f,b,w,l,v)}),e.draw_an_object(n,"#nodes",".node",o,"node_id",function(e){return t.create_node(e,o,s)},function(e){return t.update_node(e,i,E,S,c,h,p,d,m)}),e.draw_an_object(n,"#text-labels",".text-label",u,"text_label_id",function(e){return t.create_text_label(e)},function(e){return t.update_text_label(e,g,y)})}function k(){var e=[];for(var t in this.reactions)e.push(t);this.draw_these_reactions(e)}function L(n){var r=this.scale,i=this.reactions,s=this.nodes,o=this.defs,u=this.default_reaction_color,a=this.behavior.bezier_drag,f=this.behavior.reaction_label_drag,l=this.has_reaction_data(),c=this.settings.data_styles.reaction,h=this.beziers_enabled,p={},d=-1;while(++d0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function H(){return this.apply_metabolite_data_to_nodes(this.nodes)}function B(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function j(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function F(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function I(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function R(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function U(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function W(){this.sel.selectAll(".selected").classed("selected",!1)}function X(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function V(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function $(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):n.classed("selected",function(e){return t===e});var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function J(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function K(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function Q(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function G(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function Y(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function Z(t,n,r){var i=this.segments_and_reactions_for_nodes(t),s=i.reactions,o=i.segment_objs_w_segments,u=e.clone(t),a=e.clone(o),f=e.clone(s),l=e.clone(n),c=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&this.draw_everything()}.bind(this);c(t,s,o,n),this.undo_stack.push(function(){this.extend_nodes(u),this.extend_reactions(f);var i=Object.keys(f);a.forEach(function(e){var t=e.segment;this.reactions[e.reaction_id].segments[e.segment_id]=t,[t.from_node_id,t.to_node_id].forEach(function(t){if(t in u)return;var n=this.nodes[t];n.connected_segments.push({reaction_id:e.reaction_id,segment_id:e.segment_id})}.bind(this)),i.indexOf(e.reaction_id)==-1&&i.push(e.reaction_id)}.bind(this));if(this.has_reaction_data()){var c=this.update_reaction_data_domain();c?this.draw_all_reactions():this.draw_these_reactions(i)}else r&&this.draw_these_reactions(i);if(this.has_metabolite_data()){var c=this.update_metabolite_data_domain();r&&(c?this.draw_all_nodes():this.draw_these_nodes(Object.keys(u)))}else r&&this.draw_these_nodes(Object.keys(u));e.extend(this.text_labels,l),r&&this.draw_these_text_labels(Object.keys(l)),n=e.clone(l),t=e.clone(u),o=e.clone(a),s=e.clone(f)}.bind(this),function(){c(t,s,o,n)}.bind(this))}function et(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function tt(e){e.forEach(function(e){var t=this.reactions[e.reaction_id];if(!(e.segment_id in t.segments))return;var n=t.segments[e.segment_id];[n.from_node_id,n.to_node_id].forEach(function(t){if(!(t in this.nodes))return;var n=this.nodes[t];n.connected_segments=n.connected_segments.filter(function(t){return t.segment_id!=e.segment_id})}.bind(this)),delete t.segments[e.segment_id]}.bind(this))}function nt(e){e.forEach(function(e){delete this.reactions[e];var t=this.search_index.remove("r"+e);t||console.warn("Could not find deleted reaction in search index")}.bind(this))}function rt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function it(){this.toggle_beziers(!0)}function st(){this.toggle_beziers(!1)}function ot(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_everything(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function ut(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.draw_everything()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function at(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function ft(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function lt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function ct(t,n,r){function d(e,t,n){this.extend_reactions(t),this.delete_node_data([n]),this.extend_nodes(e);if(this.has_reaction_data()){var r=this.apply_reaction_data_to_reactions(t);r?this.draw_all_reactions():this.draw_these_reactions(Object.keys(t))}else this.draw_these_reactions(Object.keys(t));if(this.has_metabolite_data()){var r=this.apply_metabolite_data_to_nodes(e);r?this.draw_all_nodes():this.draw_these_nodes(Object.keys(e))}else this.draw_these_nodes(Object.keys(e));for(var i in e){var s=e[i];if(s.node_is_primary&&i!=n){this.select_metabolite_with_id(i);var o={x:s.x,y:s.y};this.zoom_container&&this.zoom_container.translate_off_screen(o)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions;d.apply(this,[f,l,n]);var c=e.clone(f),h=e.clone(l),p=this;this.undo_stack.push(function(){delete f[n],p.delete_node_data(Object.keys(f)),p.delete_reaction_data(Object.keys(l)),V.apply(p,[n]),f=e.clone(c),l=e.clone(h),p.draw_everything()},function(){d.apply(p,[f,l,n])})}function ht(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function pt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function dt(t){var n=[],r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n.push(u),t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function vt(e){this._zoom_extent(e,"nodes")}function mt(e){this._zoom_extent(e,"canvas")}function gt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function yt(){return this.zoom_container.get_size()}function bt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function wt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Et(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function St(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function xt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function Tt(){e.download_json(this.map_for_export(),"saved_map")}function Nt(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Ct(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:z,select_none:W,invert_selection:X,select_selectable:$,select_metabolite_with_id:V,select_single_node:J,deselect_nodes:K,select_text_label:Q,deselect_text_labels:G,new_reaction_from_scratch:ut,new_reaction_for_metabolite:ct,cycle_primary_node:ht,make_selected_node_primary:pt,extend_nodes:at,extend_reactions:ft,edit_text_label:lt,delete_selected:Y,delete_selectable:Z,delete_node_data:et,delete_segment_data:tt,delete_reaction_data:nt,delete_text_label_data:rt,get_selected_node_ids:I,get_selected_nodes:q,get_selected_text_label_ids:R,get_selected_text_labels:U,segments_and_reactions_for_nodes:dt,has_reaction_data:T,has_metabolite_data:N,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,draw_all_nodes:A,draw_these_nodes:O,draw_these_text_labels:M,apply_reaction_data_to_map:_,apply_reaction_data_to_reactions:D,update_reaction_data_domain:P,apply_metabolite_data_to_map:H,apply_metabolite_data_to_nodes:B,update_metabolite_data_domain:j,get_selected_node_ids:I,toggle_beziers:ot,hide_beziers:st,show_beziers:it,zoom_extent_nodes:vt,zoom_extent_canvas:mt,_zoom_extent:gt,get_size:yt,zoom_to_reaction:bt,zoom_to_node:wt,highlight_reaction:Et,highlight_node:St,highlight:xt,save:Tt,map_for_export:Nt,save_svg:Ct},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","default_reaction_color","has_reaction_data","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,o,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","default_reaction_color","has_reaction_data","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(o&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return s}).style("stroke-width",function(e){if(o&&u.indexOf("size")!==-1){var t=e.data;return n.reaction_size(t===null?0:t)}return n.reaction_size(0)});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(o&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(o&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return s}).attr("stroke",function(e){if(o&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return s}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function k(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function L(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.default_reaction_color,this.has_reaction_data(),this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function A(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function O(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function M(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function _(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function D(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function P(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function H(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function B(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function j(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function F(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function I(){this.toggle_beziers(!0)}function q(){this.toggle_beziers(!1)}function R(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function U(){return this.apply_reaction_data_to_reactions(this.reactions)}function z(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function W(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function X(){return this.apply_metabolite_data_to_nodes(this.nodes)}function V(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function $(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function J(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function K(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function Q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function G(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Y(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function Z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function et(){this.sel.selectAll(".selected").classed("selected",!1)}function tt(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function nt(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function rt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function it(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function st(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function ot(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function ut(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function at(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ft(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function lt(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ct(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function ht(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function pt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function dt(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function vt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function mt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function gt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function yt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),nt.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function bt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function wt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function Et(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function St(e){this._zoom_extent(e,"nodes")}function xt(e){this._zoom_extent(e,"canvas")}function Tt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function Nt(){return this.zoom_container.get_size()}function Ct(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function kt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Lt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function At(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Ot(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function Mt(){e.download_json(this.map_for_export(),"saved_map")}function _t(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Dt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:Z,select_none:et,invert_selection:tt,select_selectable:rt,select_metabolite_with_id:nt,select_single_node:it,deselect_nodes:st,select_text_label:ot,deselect_text_labels:ut,new_reaction_from_scratch:dt,new_reaction_for_metabolite:yt,cycle_primary_node:bt,make_selected_node_primary:wt,extend_nodes:vt,extend_reactions:mt,edit_text_label:gt,delete_selected:at,delete_selectable:ft,delete_node_data:lt,delete_segment_data:ct,delete_reaction_data:ht,delete_text_label_data:pt,get_selected_node_ids:K,get_selected_nodes:Q,get_selected_text_label_ids:G,get_selected_text_labels:Y,segments_and_reactions_for_nodes:Et,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,clear_deleted_reactions:A,draw_all_nodes:O,draw_these_nodes:M,clear_deleted_nodes:_,draw_all_text_labels:D,draw_these_text_labels:P,clear_deleted_text_labels:H,draw_all_beziers:B,draw_these_beziers:j,clear_deleted_beziers:F,toggle_beziers:R,hide_beziers:q,show_beziers:I,has_reaction_data:T,has_metabolite_data:N,apply_reaction_data_to_map:U,apply_reaction_data_to_reactions:z,update_reaction_data_domain:W,apply_metabolite_data_to_map:X,apply_metabolite_data_to_nodes:V,update_metabolite_data_domain:$,zoom_extent_nodes:St,zoom_extent_canvas:xt,_zoom_extent:Tt,get_size:Nt,zoom_to_reaction:Ct,zoom_to_node:kt,highlight_reaction:Lt,highlight_node:At,highlight:Ot,save:Mt,map_for_export:_t,save_svg:Dt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() + + @@ -12,7 +13,9 @@
-

ESCHER

+
+

ESCHER

+
@@ -45,18 +48,20 @@

Options

+ +
+
+

FAQ

+
    +
  1. How do I cite Escher?

    +

    Escher has not yet been published in a peer-review journal, but, in + the meantime, you can cite the code by DOI: [Fill in for release v1].

    +
  2. +
+
+
- -
-

FAQ

-
    -
  1. How do I cite Escher?

    -

    Escher has not yet been published in a peer-review journal, but, in - the meantime, you can cite the code by DOI: [Fill in for release v1].

    -
  2. -
-
diff --git a/spec/javascripts/BuilderSpec.js b/spec/javascripts/BuilderSpec.js index ce66f564..2925fe26 100644 --- a/spec/javascripts/BuilderSpec.js +++ b/spec/javascripts/BuilderSpec.js @@ -7,7 +7,6 @@ describe('Builder', function() { b = escher.Builder({ selection: sel, map: get_map() }); expect(sel.select('svg').node()).toBe(b.map.svg.node()); - expect(sel.selectAll('#membranes')[0].length).toEqual(1); expect(sel.selectAll('#nodes')[0].length).toEqual(1); expect(sel.selectAll('.node')[0].length).toEqual(31); expect(sel.selectAll('#reactions')[0].length).toEqual(1); From b199d030c0c88fe0dc20dd1f77aafe96f3c398db Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sat, 6 Sep 2014 20:58:35 -0700 Subject: [PATCH 13/33] Added no data styles. Clamp size scales. --- escher/css/builder-embed.css | 7 +- escher/css/builder.css | 4 + escher/js/src/Builder.js | 12 +- escher/js/src/Map.js | 79 +---------- escher/js/src/Scale.js | 8 +- escher/js/src/Settings.js | 61 ++++++++- escher/js/src/SettingsBar.js | 18 +++ escher/js/src/draw.js | 39 +++--- escher/lib/escher.1.0.0b3.js | 217 ++++++++++++++++--------------- escher/lib/escher.1.0.0b3.min.js | 2 +- escher/plots.py | 6 +- escher/tests/test_plots.py | 7 + 12 files changed, 246 insertions(+), 214 deletions(-) diff --git a/escher/css/builder-embed.css b/escher/css/builder-embed.css index 2406a78e..2fec890e 100644 --- a/escher/css/builder-embed.css +++ b/escher/css/builder-embed.css @@ -50,10 +50,13 @@ stroke: rgb(5, 2, 0); } .segment { - stroke: grey; - stroke-width: 3px; + stroke: #334E75; + stroke-width: 6px; fill: none; } +.arrowhead { + fill: #334E75; +} .membrane { fill: none; stroke: rgb(255, 187, 0); diff --git a/escher/css/builder.css b/escher/css/builder.css index 073d1d81..b1af80f6 100644 --- a/escher/css/builder.css +++ b/escher/css/builder.css @@ -135,6 +135,10 @@ width: 100%; text-align: left; } +.no-data-input { + width: 23%; + margin: 0 4px 0 4px; +} .style-span { margin: 0 4px; } diff --git a/escher/js/src/Builder.js b/escher/js/src/Builder.js index c6f9d53c..5613c2da 100644 --- a/escher/js/src/Builder.js +++ b/escher/js/src/Builder.js @@ -54,13 +54,17 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C reaction_domain: [-10, 0, 10], reaction_color_range: ['rgb(200,200,200)', 'rgb(150,150,255)', 'purple'], reaction_size_range: [4, 8, 12], + reaction_no_data_color: 'rgb(220,220,220)', + reaction_no_data_size: 4, metabolite_data: null, metabolite_data_path: null, metabolite_styles: ['color', 'size', 'text'], auto_metabolite_domain: true, metabolite_domain: [-10, 0, 10], metabolite_color_range: ['green', 'white', 'red'], - metabolite_size_range: [6, 8, 10] + metabolite_size_range: [6, 8, 10], + metabolite_no_data_color: 'white', + metabolite_no_data_size: 6 }); // initialize the settings @@ -74,7 +78,11 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C { reaction: { color: this.options.reaction_color_range, size: this.options.reaction_size_range }, metabolite: { color: this.options.metabolite_color_range, - size: this.options.metabolite_size_range } } + size: this.options.metabolite_size_range } }, + { reaction: { color: this.options.reaction_no_data_color, + size: this.options.reaction_no_data_size }, + metabolite: { color: this.options.metabolite_no_data_color, + size: this.options.metabolite_no_data_size } } ); if (utils.check_for_parent_tag(this.options.selection, 'svg')) { diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index 7e85271f..9d4feeba 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -38,9 +38,6 @@ define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackMan // more setup setup_containers: setup_containers, reset_containers: reset_containers, - // scales - get_scale: get_scale, - set_scale: set_scale, // appearance set_status: set_status, set_model: set_model, @@ -138,9 +135,6 @@ define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackMan width: size.width*3, height: size.height*3}; } - // defaults - this.default_reaction_color = '#334E75', - // set up the defs this.svg = svg; this.defs = utils.setup_defs(svg, css); @@ -357,77 +351,6 @@ define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackMan .remove(); } - // ------------------------------------------------------------------------- - // Scales - - function get_scale(data, type) { - /** Get a reaction or metabolite scale. - - Arguments - --------- - - data: The type of data. Options are 'reaction' or 'metabolite'. - - type: The type of scale to set. Options are 'size' and 'color'. - - */ - - if (data=='reaction' && type=='size') { - return this.scale.reaction_size; - } else if (data=='reaction' && type=='color') { - return this.scale.reaction_color; - } else if (data=='metabolite' && type=='size') { - return this.scale.metabolite_size; - } else if (data=='metabolite' && type=='color') { - return this.scale.metabolite_color; - } else { - throw Error('Bad value for data or type: ' + data + ', ' + type); - } - } - - function set_scale(data, type, domain, range) { - /** Set a reaction or metabolite scale. - - Arguments - --------- - - data: The type of data. Options are 'reaction' or 'metabolite'. - - type: The type of scale to set. Options are 'size' and 'color'. - - domain: The new scale domain. If domain is *null*, then the existing - domain is used. If any settings.auto_*_domain is true, then, this input - is ignored. - - */ - - if (domain===undefined) domain = null; - if (range===undefined) range = null; - - if (domain !== null && (this.settings.auto_domain['reaction']==true || - this.settings.auto_domain['metabolite']==true)) { - console.warn('Cannot set domain manually if auto_*_domain is true'); - domain = null; - } - - if (data=='reaction' && type=='size') { - set_this_scale(this.scale.reaction_size, domain, range); - } else if (data=='reaction' && type=='color') { - set_this_scale(this.scale.reaction_color, domain, range); - } else if (data=='metabolite' && type=='size') { - set_this_scale(this.scale.metabolite_size, domain, range); - } else if (data=='metabolite' && type=='color') { - set_this_scale(this.scale.metabolite_color, domain, range); - } else { - throw Error('Bad value for data or type: ' + data + ', ' + type); - } - - function set_this_scale(a_scale, a_domain, a_range) { - if (a_domain !== null) a_scale.domain(a_domain); - if (a_range !== null) a_scale.range(a_range); - } - } - // ------------------------------------------------------------------------- // Appearance @@ -558,8 +481,8 @@ define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackMan this.scale, this.nodes, this.defs, - this.default_reaction_color, this.has_reaction_data(), + this.settings.no_data['reaction'], this.settings.data_styles['reaction'], this.behavior.reaction_label_drag); }.bind(this); diff --git a/escher/js/src/Scale.js b/escher/js/src/Scale.js index 8dc5495c..08484dd3 100644 --- a/escher/js/src/Scale.js +++ b/escher/js/src/Scale.js @@ -15,10 +15,10 @@ define(["utils"], function(utils) { this.x_size = d3.scale.linear(); this.y_size = d3.scale.linear(); this.size = d3.scale.linear(); - this.reaction_color = d3.scale.linear(); - this.reaction_size = d3.scale.linear(); - this.metabolite_size = d3.scale.linear(); - this.metabolite_color = d3.scale.linear(); + this.reaction_color = d3.scale.linear().clamp(true); + this.reaction_size = d3.scale.linear().clamp(true); + this.metabolite_color = d3.scale.linear().clamp(true); + this.metabolite_size = d3.scale.linear().clamp(true); this.scale_path = function(path) { var x_fn = this.x, y_fn = this.y; // TODO: scale arrow width diff --git a/escher/js/src/Settings.js b/escher/js/src/Settings.js index 02caa6bb..8deeb5d3 100644 --- a/escher/js/src/Settings.js +++ b/escher/js/src/Settings.js @@ -12,6 +12,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { set_domain_value: set_domain_value, set_domain: set_domain, set_range_value: set_range_value, + set_no_data_value: set_no_data_value, hold_changes: hold_changes, abandon_changes: abandon_changes, accept_changes: accept_changes }; @@ -25,7 +26,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { } // instance methods - function init(def_styles, def_auto_domain, def_domain, def_range) { + function init(def_styles, def_auto_domain, def_domain, def_range, def_no_data) { // defaults if (def_styles===undefined) def_styles = { reaction: ['color', 'size', 'abs', 'text'], @@ -41,6 +42,11 @@ define(["utils", "lib/bacon"], function(utils, bacon) { size: [4, 8, 12] }, metabolite: { color: ['green', 'white', 'red'], size: [6, 8, 10] } }; + if (def_no_data===undefined) + def_no_data = { reaction: { color: 'rgb(220,220,220)', + size: 4 }, + metabolite: { color: 'white', + size: 6 } }; // event streams this.data_styles = {}; @@ -55,6 +61,9 @@ define(["utils", "lib/bacon"], function(utils, bacon) { this.range = {}; this.range_bus = {}; this.range_stream = {}; + this.no_data = {}; + this.no_data_bus = {}; + this.no_data_stream = {}; // manage accepting/abandoning changes this.status_bus = new bacon.Bus(); @@ -178,6 +187,35 @@ define(["utils", "lib/bacon"], function(utils, bacon) { }.bind(this)); }.bind(this)); + + // set up the no data settings + this.no_data_bus[type] = {}; + this.no_data_stream[type] = {}; + this.no_data[type] = {}; + ['color', 'size'].forEach(function(no_data_type) { + // make the bus + this.no_data_bus[type][no_data_type] = new bacon.Bus(); + // make a new constant for the input default + this.no_data_stream[type][no_data_type] = this.no_data_bus[type][no_data_type] + // conditionally accept changes + .convert_to_conditional_stream(this.status_bus) + // combine into state array + .scan([], function(current, value) { + return value; + }) + // force updates + .force_update_with_bus(this.force_update_bus); + + // get the latest + this.no_data_stream[type][no_data_type].onValue(function(v) { + this.no_data[type][no_data_type] = v; + }.bind(this)); + + // push the default + var def = def_no_data[type][no_data_type]; + this.no_data_bus[type][no_data_type].push(def); + + }.bind(this)); }.bind(this)); // definitions @@ -239,6 +277,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { }); } } + function set_auto_domain(type, on_off) { /** Turn auto domain setting on or off. @@ -252,6 +291,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { this.auto_domain_bus[type].push(on_off); } + function change_data_style(type, style, on_off) { /** Change the data style. @@ -268,6 +308,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { this.data_styles_bus[type].push({ style: style, on_off: on_off }); } + function set_domain_value(type, index, value) { /** Change a domain value. @@ -283,6 +324,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { this.domain_bus[type].push({ index: index, value: value }); } + function set_domain(type, domain) { /** Change a domain. @@ -297,6 +339,7 @@ define(["utils", "lib/bacon"], function(utils, bacon) { this.domain_bus[type].push({ index: i, value: d }); }.bind(this)); } + function set_range_value(type, range_type, index, value) { /** Change a range value. @@ -314,6 +357,22 @@ define(["utils", "lib/bacon"], function(utils, bacon) { this.range_bus[type][range_type].push({ index: index, value: value }); } + + function set_no_data_value(type, no_data_type, value) { + /** Change a no_data value. + + type: 'reaction' or 'metabolite' + + no_data_type: 'color' or 'size' + + value: The new value + + */ + check_type(type); + + this.no_data_bus[type][no_data_type].push(value); + } + function hold_changes() { this.status_bus.push('hold'); } diff --git a/escher/js/src/SettingsBar.js b/escher/js/src/SettingsBar.js index b6709f2c..c6a54434 100644 --- a/escher/js/src/SettingsBar.js +++ b/escher/js/src/SettingsBar.js @@ -197,6 +197,24 @@ define(["utils", "CallbackManager", "lib/bacon"], function(utils, CallbackManage }); }); + // no data + var r = t.append('tr').append('td').attr('colspan', '5'); + [['color', 'No data color'], ['size', 'No data size']].forEach(function(range_type_ar) { + r.append('span').text(range_type_ar[1] + ':'); + r.append('input').attr('class', 'no-data-input') + .each(function() { + bacon.fromEventTarget(this, 'change') + .onValue(function(event) { + settings.set_no_data_value(type, range_type_ar[0], + event.target.value); + }); + + settings.no_data_stream[type][range_type_ar[0]].onValue(function(ar) { + this.value = ar; + }.bind(this)); + }); + }); + // styles t.append('tr').call(function(r) { r.append('td').text('Styles:'); diff --git a/escher/js/src/draw.js b/escher/js/src/draw.js index 6f3e8b2b..4dac8c4d 100644 --- a/escher/js/src/draw.js +++ b/escher/js/src/draw.js @@ -48,18 +48,17 @@ define(['utils', 'data_styles'], function(utils, data_styles) { } function update_reaction(update_selection, scale, drawn_nodes, - defs, default_reaction_color, has_reaction_data, - reaction_data_styles, - label_drag_behavior) { + defs, has_reaction_data, + no_data_style, reaction_data_styles, label_drag_behavior) { utils.check_undefined(arguments, ['update_selection', 'scale', 'drawn_nodes', - 'defs', 'default_reaction_color', 'has_reaction_data', - 'reaction_data_styles', + 'defs', 'has_reaction_data', + 'no_data_style', 'reaction_data_styles', 'label_drag_behavior']); // update reaction label update_selection.select('.reaction-label') - .call(function(sel) { return update_reaction_label(sel, has_reaction_data, + .call(function(sel) { return update_reaction_label(sel, has_reaction_data, reaction_data_styles, label_drag_behavior); }); @@ -68,8 +67,8 @@ define(['utils', 'data_styles'], function(utils, data_styles) { create_segment, function(sel) { return update_segment(sel, scale, drawn_nodes, defs, - default_reaction_color, - has_reaction_data, reaction_data_styles); + has_reaction_data, + no_data_style, reaction_data_styles); }, function(sel) { sel.remove(); @@ -178,12 +177,12 @@ define(['utils', 'data_styles'], function(utils, data_styles) { } function update_segment(update_selection, scale, drawn_nodes, - defs, default_reaction_color, - has_reaction_data, reaction_data_styles) { + defs, has_reaction_data, no_data_style, + reaction_data_styles) { utils.check_undefined(arguments, ['update_selection', 'scale', 'drawn_nodes', 'defs', - 'default_reaction_color', 'has_reaction_data', + 'no_data_style', 'reaction_data_styles']); // update segment attributes @@ -225,17 +224,17 @@ define(['utils', 'data_styles'], function(utils, data_styles) { .style('stroke', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('color')!==-1) { var f = d.data; - return scale.reaction_color(f===null ? 0 : f); + return f===null ? no_data_style['color'] : scale.reaction_color(f); } else { - return default_reaction_color; + return null; } }) .style('stroke-width', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('size')!==-1) { var f = d.data; - return scale.reaction_size(f===null ? 0 : f); + return f===null ? no_data_style['size'] : scale.reaction_size(f); } else { - return scale.reaction_size(0); + return null; } }); @@ -290,7 +289,7 @@ define(['utils', 'data_styles'], function(utils, data_styles) { return 'M'+[-markerWidth/2, 0]+' L'+[0, markerHeight]+' L'+[markerWidth/2, 0]+' Z'; }).attr('transform', function(d) { return 'translate('+d.x+','+d.y+')rotate('+d.rotation+')'; - }).attr('fill', function(d) { + }).style('fill', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('color')!==-1) { if (d.show_arrowhead_flux) { // show the flux @@ -302,16 +301,16 @@ define(['utils', 'data_styles'], function(utils, data_styles) { } } // default fill color - return default_reaction_color; - }).attr('stroke', function(d) { + return null; + }).style('stroke', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('color')!==-1) { // show the flux color in the stroke whether or not the fill is present var f = d.data; return scale.reaction_color(f===null ? 0 : f); } // default stroke color - return default_reaction_color; - });; + return null; + }); // remove arrowheads.exit().remove(); } diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 9f2dbada..34172956 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1526,18 +1526,17 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { } function update_reaction(update_selection, scale, drawn_nodes, - defs, default_reaction_color, has_reaction_data, - reaction_data_styles, - label_drag_behavior) { + defs, has_reaction_data, + no_data_style, reaction_data_styles, label_drag_behavior) { utils.check_undefined(arguments, ['update_selection', 'scale', 'drawn_nodes', - 'defs', 'default_reaction_color', 'has_reaction_data', - 'reaction_data_styles', + 'defs', 'has_reaction_data', + 'no_data_style', 'reaction_data_styles', 'label_drag_behavior']); // update reaction label update_selection.select('.reaction-label') - .call(function(sel) { return update_reaction_label(sel, has_reaction_data, + .call(function(sel) { return update_reaction_label(sel, has_reaction_data, reaction_data_styles, label_drag_behavior); }); @@ -1546,8 +1545,8 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { create_segment, function(sel) { return update_segment(sel, scale, drawn_nodes, defs, - default_reaction_color, - has_reaction_data, reaction_data_styles); + has_reaction_data, + no_data_style, reaction_data_styles); }, function(sel) { sel.remove(); @@ -1656,12 +1655,12 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { } function update_segment(update_selection, scale, drawn_nodes, - defs, default_reaction_color, - has_reaction_data, reaction_data_styles) { + defs, has_reaction_data, no_data_style, + reaction_data_styles) { utils.check_undefined(arguments, ['update_selection', 'scale', 'drawn_nodes', 'defs', - 'default_reaction_color', 'has_reaction_data', + 'no_data_style', 'reaction_data_styles']); // update segment attributes @@ -1703,17 +1702,17 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { .style('stroke', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('color')!==-1) { var f = d.data; - return scale.reaction_color(f===null ? 0 : f); + return f===null ? no_data_style['color'] : scale.reaction_color(f); } else { - return default_reaction_color; + return null; } }) .style('stroke-width', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('size')!==-1) { var f = d.data; - return scale.reaction_size(f===null ? 0 : f); + return f===null ? no_data_style['size'] : scale.reaction_size(f); } else { - return scale.reaction_size(0); + return null; } }); @@ -1768,7 +1767,7 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { return 'M'+[-markerWidth/2, 0]+' L'+[0, markerHeight]+' L'+[markerWidth/2, 0]+' Z'; }).attr('transform', function(d) { return 'translate('+d.x+','+d.y+')rotate('+d.rotation+')'; - }).attr('fill', function(d) { + }).style('fill', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('color')!==-1) { if (d.show_arrowhead_flux) { // show the flux @@ -1780,16 +1779,16 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { } } // default fill color - return default_reaction_color; - }).attr('stroke', function(d) { + return null; + }).style('stroke', function(d) { if (has_reaction_data && reaction_data_styles.indexOf('color')!==-1) { // show the flux color in the stroke whether or not the fill is present var f = d.data; return scale.reaction_color(f===null ? 0 : f); } // default stroke color - return default_reaction_color; - });; + return null; + }); // remove arrowheads.exit().remove(); } @@ -3344,10 +3343,10 @@ define('Scale',["utils"], function(utils) { this.x_size = d3.scale.linear(); this.y_size = d3.scale.linear(); this.size = d3.scale.linear(); - this.reaction_color = d3.scale.linear(); - this.reaction_size = d3.scale.linear(); - this.metabolite_size = d3.scale.linear(); - this.metabolite_color = d3.scale.linear(); + this.reaction_color = d3.scale.linear().clamp(true); + this.reaction_size = d3.scale.linear().clamp(true); + this.metabolite_color = d3.scale.linear().clamp(true); + this.metabolite_size = d3.scale.linear().clamp(true); this.scale_path = function(path) { var x_fn = this.x, y_fn = this.y; // TODO: scale arrow width @@ -7046,9 +7045,6 @@ define('Map',['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'Callb // more setup setup_containers: setup_containers, reset_containers: reset_containers, - // scales - get_scale: get_scale, - set_scale: set_scale, // appearance set_status: set_status, set_model: set_model, @@ -7146,9 +7142,6 @@ define('Map',['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'Callb width: size.width*3, height: size.height*3}; } - // defaults - this.default_reaction_color = '#334E75', - // set up the defs this.svg = svg; this.defs = utils.setup_defs(svg, css); @@ -7365,77 +7358,6 @@ define('Map',['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'Callb .remove(); } - // ------------------------------------------------------------------------- - // Scales - - function get_scale(data, type) { - /** Get a reaction or metabolite scale. - - Arguments - --------- - - data: The type of data. Options are 'reaction' or 'metabolite'. - - type: The type of scale to set. Options are 'size' and 'color'. - - */ - - if (data=='reaction' && type=='size') { - return this.scale.reaction_size; - } else if (data=='reaction' && type=='color') { - return this.scale.reaction_color; - } else if (data=='metabolite' && type=='size') { - return this.scale.metabolite_size; - } else if (data=='metabolite' && type=='color') { - return this.scale.metabolite_color; - } else { - throw Error('Bad value for data or type: ' + data + ', ' + type); - } - } - - function set_scale(data, type, domain, range) { - /** Set a reaction or metabolite scale. - - Arguments - --------- - - data: The type of data. Options are 'reaction' or 'metabolite'. - - type: The type of scale to set. Options are 'size' and 'color'. - - domain: The new scale domain. If domain is *null*, then the existing - domain is used. If any settings.auto_*_domain is true, then, this input - is ignored. - - */ - - if (domain===undefined) domain = null; - if (range===undefined) range = null; - - if (domain !== null && (this.settings.auto_domain['reaction']==true || - this.settings.auto_domain['metabolite']==true)) { - console.warn('Cannot set domain manually if auto_*_domain is true'); - domain = null; - } - - if (data=='reaction' && type=='size') { - set_this_scale(this.scale.reaction_size, domain, range); - } else if (data=='reaction' && type=='color') { - set_this_scale(this.scale.reaction_color, domain, range); - } else if (data=='metabolite' && type=='size') { - set_this_scale(this.scale.metabolite_size, domain, range); - } else if (data=='metabolite' && type=='color') { - set_this_scale(this.scale.metabolite_color, domain, range); - } else { - throw Error('Bad value for data or type: ' + data + ', ' + type); - } - - function set_this_scale(a_scale, a_domain, a_range) { - if (a_domain !== null) a_scale.domain(a_domain); - if (a_range !== null) a_scale.range(a_range); - } - } - // ------------------------------------------------------------------------- // Appearance @@ -7566,8 +7488,8 @@ define('Map',['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'Callb this.scale, this.nodes, this.defs, - this.default_reaction_color, this.has_reaction_data(), + this.settings.no_data['reaction'], this.settings.data_styles['reaction'], this.behavior.reaction_label_drag); }.bind(this); @@ -10515,6 +10437,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { set_domain_value: set_domain_value, set_domain: set_domain, set_range_value: set_range_value, + set_no_data_value: set_no_data_value, hold_changes: hold_changes, abandon_changes: abandon_changes, accept_changes: accept_changes }; @@ -10528,7 +10451,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { } // instance methods - function init(def_styles, def_auto_domain, def_domain, def_range) { + function init(def_styles, def_auto_domain, def_domain, def_range, def_no_data) { // defaults if (def_styles===undefined) def_styles = { reaction: ['color', 'size', 'abs', 'text'], @@ -10544,6 +10467,11 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { size: [4, 8, 12] }, metabolite: { color: ['green', 'white', 'red'], size: [6, 8, 10] } }; + if (def_no_data===undefined) + def_no_data = { reaction: { color: 'rgb(220,220,220)', + size: 4 }, + metabolite: { color: 'white', + size: 6 } }; // event streams this.data_styles = {}; @@ -10558,6 +10486,9 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { this.range = {}; this.range_bus = {}; this.range_stream = {}; + this.no_data = {}; + this.no_data_bus = {}; + this.no_data_stream = {}; // manage accepting/abandoning changes this.status_bus = new bacon.Bus(); @@ -10681,6 +10612,35 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { }.bind(this)); }.bind(this)); + + // set up the no data settings + this.no_data_bus[type] = {}; + this.no_data_stream[type] = {}; + this.no_data[type] = {}; + ['color', 'size'].forEach(function(no_data_type) { + // make the bus + this.no_data_bus[type][no_data_type] = new bacon.Bus(); + // make a new constant for the input default + this.no_data_stream[type][no_data_type] = this.no_data_bus[type][no_data_type] + // conditionally accept changes + .convert_to_conditional_stream(this.status_bus) + // combine into state array + .scan([], function(current, value) { + return value; + }) + // force updates + .force_update_with_bus(this.force_update_bus); + + // get the latest + this.no_data_stream[type][no_data_type].onValue(function(v) { + this.no_data[type][no_data_type] = v; + }.bind(this)); + + // push the default + var def = def_no_data[type][no_data_type]; + this.no_data_bus[type][no_data_type].push(def); + + }.bind(this)); }.bind(this)); // definitions @@ -10742,6 +10702,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { }); } } + function set_auto_domain(type, on_off) { /** Turn auto domain setting on or off. @@ -10755,6 +10716,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { this.auto_domain_bus[type].push(on_off); } + function change_data_style(type, style, on_off) { /** Change the data style. @@ -10771,6 +10733,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { this.data_styles_bus[type].push({ style: style, on_off: on_off }); } + function set_domain_value(type, index, value) { /** Change a domain value. @@ -10786,6 +10749,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { this.domain_bus[type].push({ index: index, value: value }); } + function set_domain(type, domain) { /** Change a domain. @@ -10800,6 +10764,7 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { this.domain_bus[type].push({ index: i, value: d }); }.bind(this)); } + function set_range_value(type, range_type, index, value) { /** Change a range value. @@ -10817,6 +10782,22 @@ define('Settings',["utils", "lib/bacon"], function(utils, bacon) { this.range_bus[type][range_type].push({ index: index, value: value }); } + + function set_no_data_value(type, no_data_type, value) { + /** Change a no_data value. + + type: 'reaction' or 'metabolite' + + no_data_type: 'color' or 'size' + + value: The new value + + */ + check_type(type); + + this.no_data_bus[type][no_data_type].push(value); + } + function hold_changes() { this.status_bus.push('hold'); } @@ -11030,6 +11011,24 @@ define('SettingsBar',["utils", "CallbackManager", "lib/bacon"], function(utils, }); }); + // no data + var r = t.append('tr').append('td').attr('colspan', '5'); + [['color', 'No data color'], ['size', 'No data size']].forEach(function(range_type_ar) { + r.append('span').text(range_type_ar[1] + ':'); + r.append('input').attr('class', 'no-data-input') + .each(function() { + bacon.fromEventTarget(this, 'change') + .onValue(function(event) { + settings.set_no_data_value(type, range_type_ar[0], + event.target.value); + }); + + settings.no_data_stream[type][range_type_ar[0]].onValue(function(ar) { + this.value = ar; + }.bind(this)); + }); + }); + // styles t.append('tr').call(function(r) { r.append('td').text('Styles:'); @@ -11274,13 +11273,17 @@ define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', ' reaction_domain: [-10, 0, 10], reaction_color_range: ['rgb(200,200,200)', 'rgb(150,150,255)', 'purple'], reaction_size_range: [4, 8, 12], + reaction_no_data_color: 'rgb(220,220,220)', + reaction_no_data_size: 4, metabolite_data: null, metabolite_data_path: null, metabolite_styles: ['color', 'size', 'text'], auto_metabolite_domain: true, metabolite_domain: [-10, 0, 10], metabolite_color_range: ['green', 'white', 'red'], - metabolite_size_range: [6, 8, 10] + metabolite_size_range: [6, 8, 10], + metabolite_no_data_color: 'white', + metabolite_no_data_size: 6 }); // initialize the settings @@ -11294,7 +11297,11 @@ define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', ' { reaction: { color: this.options.reaction_color_range, size: this.options.reaction_size_range }, metabolite: { color: this.options.metabolite_color_range, - size: this.options.metabolite_size_range } } + size: this.options.metabolite_size_range } }, + { reaction: { color: this.options.reaction_no_data_color, + size: this.options.reaction_no_data_size }, + metabolite: { color: this.options.metabolite_no_data_color, + size: this.options.metabolite_no_data_size } } ); if (utils.check_for_parent_tag(this.options.selection, 'svg')) { diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 5a2fe869..87645f96 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","default_reaction_color","has_reaction_data","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,o,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","default_reaction_color","has_reaction_data","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(o&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return s}).style("stroke-width",function(e){if(o&&u.indexOf("size")!==-1){var t=e.data;return n.reaction_size(t===null?0:t)}return n.reaction_size(0)});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(o&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).attr("fill",function(e){if(o&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return s}).attr("stroke",function(e){if(o&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return s}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear(),this.reaction_size=d3.scale.linear(),this.metabolite_size=d3.scale.linear(),this.metabolite_color=d3.scale.linear(),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.default_reaction_color="#334E75",this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e,t){if(e=="reaction"&&t=="size")return this.scale.reaction_size;if(e=="reaction"&&t=="color")return this.scale.reaction_color;if(e=="metabolite"&&t=="size")return this.scale.metabolite_size;if(e=="metabolite"&&t=="color")return this.scale.metabolite_color;throw Error("Bad value for data or type: "+e+", "+t)}function y(e,t,n,r){function i(e,t,n){t!==null&&e.domain(t),n!==null&&e.range(n)}n===undefined&&(n=null),r===undefined&&(r=null),n!==null&&(this.settings.auto_domain["reaction"]==1||this.settings.auto_domain["metabolite"]==1)&&(console.warn("Cannot set domain manually if auto_*_domain is true"),n=null);if(e=="reaction"&&t=="size")i(this.scale.reaction_size,n,r);else if(e=="reaction"&&t=="color")i(this.scale.reaction_color,n,r);else if(e=="metabolite"&&t=="size")i(this.scale.metabolite_size,n,r);else{if(e!="metabolite"||t!="color")throw Error("Bad value for data or type: "+e+", "+t);i(this.scale.metabolite_color,n,r)}}function b(e){this.status=e,this.callback_manager.run("set_status",e)}function w(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function E(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function S(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function x(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function T(){return this.reaction_data_object!==null}function N(){return this.metabolite_data_object!==null}function C(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function k(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function L(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.default_reaction_color,this.has_reaction_data(),this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function A(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function O(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function M(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function _(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function D(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function P(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function H(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function B(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function j(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function F(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function I(){this.toggle_beziers(!0)}function q(){this.toggle_beziers(!1)}function R(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function U(){return this.apply_reaction_data_to_reactions(this.reactions)}function z(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function W(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function X(){return this.apply_metabolite_data_to_nodes(this.nodes)}function V(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function $(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function J(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function K(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function Q(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function G(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Y(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function Z(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function et(){this.sel.selectAll(".selected").classed("selected",!1)}function tt(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function nt(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function rt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function it(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function st(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function ot(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function ut(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function at(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ft(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function lt(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ct(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function ht(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function pt(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function dt(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function vt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function mt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function gt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function yt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),nt.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function bt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function wt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function Et(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function b(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function St(e){this._zoom_extent(e,"nodes")}function xt(e){this._zoom_extent(e,"canvas")}function Tt(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function Nt(){return this.zoom_container.get_size()}function Ct(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function kt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Lt(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function At(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Ot(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function Mt(){e.download_json(this.map_for_export(),"saved_map")}function _t(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Dt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,get_scale:g,set_scale:y,set_status:b,set_model:w,set_reaction_data:E,set_metabolite_data:S,clear_map:x,select_all:Z,select_none:et,invert_selection:tt,select_selectable:rt,select_metabolite_with_id:nt,select_single_node:it,deselect_nodes:st,select_text_label:ot,deselect_text_labels:ut,new_reaction_from_scratch:dt,new_reaction_for_metabolite:yt,cycle_primary_node:bt,make_selected_node_primary:wt,extend_nodes:vt,extend_reactions:mt,edit_text_label:gt,delete_selected:at,delete_selectable:ft,delete_node_data:lt,delete_segment_data:ct,delete_reaction_data:ht,delete_text_label_data:pt,get_selected_node_ids:K,get_selected_nodes:Q,get_selected_text_label_ids:G,get_selected_text_labels:Y,segments_and_reactions_for_nodes:Et,draw_everything:C,draw_all_reactions:k,draw_these_reactions:L,clear_deleted_reactions:A,draw_all_nodes:O,draw_these_nodes:M,clear_deleted_nodes:_,draw_all_text_labels:D,draw_these_text_labels:P,clear_deleted_text_labels:H,draw_all_beziers:B,draw_these_beziers:j,clear_deleted_beziers:F,toggle_beziers:R,hide_beziers:q,show_beziers:I,has_reaction_data:T,has_metabolite_data:N,apply_reaction_data_to_map:U,apply_reaction_data_to_reactions:z,update_reaction_data_domain:W,apply_metabolite_data_to_map:X,apply_metabolite_data_to_nodes:V,update_metabolite_data_domain:$,zoom_extent_nodes:St,zoom_extent_canvas:xt,_zoom_extent:Tt,get_size:Nt,zoom_to_reaction:Ct,zoom_to_node:kt,highlight_reaction:Lt,highlight_node:At,highlight:Ot,save:Mt,map_for_export:_t,save_svg:Dt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,s,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sat, 6 Sep 2014 21:19:40 -0700 Subject: [PATCH 14/33] remove little black anchors, borders on SVG export --- escher/js/src/Map.js | 13 +++++++++++++ escher/js/src/draw.js | 6 ++++-- escher/lib/escher.1.0.0b3.js | 19 +++++++++++++++++-- escher/lib/escher.1.0.0b3.min.js | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/escher/js/src/Map.js b/escher/js/src/Map.js index 9d4feeba..6bcae581 100644 --- a/escher/js/src/Map.js +++ b/escher/js/src/Map.js @@ -1806,7 +1806,9 @@ define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackMan return out; } function save_svg() { + // run the before callback this.callback_manager.run('before_svg_export'); + // turn of zoom and translate so that illustrator likes the map var window_scale = this.zoom_container.window_scale, window_translate = this.zoom_container.window_translate, @@ -1820,13 +1822,24 @@ define(['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'CallbackMan this.canvas.mouse_node.attr('width', '0px'); this.canvas.mouse_node.attr('height', '0px'); this.canvas.mouse_node.attr('transform', null); + // hide the segment control points + var hidden_sel = this.sel.selectAll('.multimarker-circle,.midmarker-circle') + .style('visibility', 'hidden'); + + // do the epxort utils.export_svg('saved_map', this.svg, true); + + // revert everything this.zoom_container.go_to(window_scale, window_translate, false); this.svg.attr('width', null); this.svg.attr('height', null); this.canvas.mouse_node.attr('width', mouse_node_size_and_trans.w); this.canvas.mouse_node.attr('height', mouse_node_size_and_trans.h); this.canvas.mouse_node.attr('transform', mouse_node_size_and_trans.transform); + // unhide the segment control points + hidden_sel.style('visibility', null); + + // run the after callback this.callback_manager.run('after_svg_export'); } }); diff --git a/escher/js/src/draw.js b/escher/js/src/draw.js index 4dac8c4d..5db665fc 100644 --- a/escher/js/src/draw.js +++ b/escher/js/src/draw.js @@ -383,8 +383,10 @@ define(['utils', 'data_styles'], function(utils, data_styles) { // create metabolite circle and label g.append('circle') .attr('class', function(d) { - if (d.node_type=='metabolite') return 'node-circle metabolite-circle'; - else return 'node-circle'; + var c = 'node-circle'; + if (d.node_type!==null) + c += (' ' + d.node_type + '-circle'); + return c; }); // .style('stroke-width', '2px'); diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 34172956..47d7955b 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1861,8 +1861,10 @@ define('draw',['utils', 'data_styles'], function(utils, data_styles) { // create metabolite circle and label g.append('circle') .attr('class', function(d) { - if (d.node_type=='metabolite') return 'node-circle metabolite-circle'; - else return 'node-circle'; + var c = 'node-circle'; + if (d.node_type!==null) + c += (' ' + d.node_type + '-circle'); + return c; }); // .style('stroke-width', '2px'); @@ -8813,7 +8815,9 @@ define('Map',['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'Callb return out; } function save_svg() { + // run the before callback this.callback_manager.run('before_svg_export'); + // turn of zoom and translate so that illustrator likes the map var window_scale = this.zoom_container.window_scale, window_translate = this.zoom_container.window_translate, @@ -8827,13 +8831,24 @@ define('Map',['utils', 'draw', 'Behavior', 'Scale', 'build', 'UndoStack', 'Callb this.canvas.mouse_node.attr('width', '0px'); this.canvas.mouse_node.attr('height', '0px'); this.canvas.mouse_node.attr('transform', null); + // hide the segment control points + var hidden_sel = this.sel.selectAll('.multimarker-circle,.midmarker-circle') + .style('visibility', 'hidden'); + + // do the epxort utils.export_svg('saved_map', this.svg, true); + + // revert everything this.zoom_container.go_to(window_scale, window_translate, false); this.svg.attr('width', null); this.svg.attr('height', null); this.canvas.mouse_node.attr('width', mouse_node_size_and_trans.w); this.canvas.mouse_node.attr('height', mouse_node_size_and_trans.h); this.canvas.mouse_node.attr('transform', mouse_node_size_and_trans.transform); + // unhide the segment control points + hidden_sel.style('visibility', null); + + // run the after callback this.callback_manager.run('after_svg_export'); } }); diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 87645f96..72df8424 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,s,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){return e.node_type=="metabolite"?"node-circle metabolite-circle":"node-circle"}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null),e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,s,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sat, 6 Sep 2014 21:34:57 -0700 Subject: [PATCH 15/33] Are you sure you want to quit? message. The new option is: never_ask_before_quit. --- escher/js/src/Builder.js | 20 ++++++++++++++++- escher/lib/escher.1.0.0b3.js | 20 ++++++++++++++++- escher/lib/escher.1.0.0b3.min.js | 2 +- escher/plots.py | 38 +++++++++++++++++++++++--------- escher/server.py | 3 ++- 5 files changed, 69 insertions(+), 14 deletions(-) diff --git a/escher/js/src/Builder.js b/escher/js/src/Builder.js index 5613c2da..3092b449 100644 --- a/escher/js/src/Builder.js +++ b/escher/js/src/Builder.js @@ -21,7 +21,8 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C _setup_simple_zoom_buttons: _setup_simple_zoom_buttons, _setup_status: _setup_status, _setup_modes: _setup_modes, - _get_keys: _get_keys }; + _get_keys: _get_keys, + _setup_confirm_before_exit: _setup_confirm_before_exit }; return Builder; @@ -46,6 +47,7 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C css_path: null, css: null, starting_reaction: null, + never_ask_before_quit: false, // applied data auto_reaction_domain: true, reaction_data_path: null, @@ -268,6 +270,10 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C else this.view_mode(); + // confirm before leaving the page + if (this.options.enable_editing && !this.options.never_ask_before_quit) + this._setup_confirm_before_exit(); + // draw this.map.draw_everything(); } @@ -718,4 +724,16 @@ define(['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', 'Brush', 'C } return keys; } + + function _setup_confirm_before_exit() { + /** Ask if the user wants to exit the page (to avoid unplanned refresh). + + */ + + window.onbeforeunload = function(e) { + // If we haven't been passed the event get the window.event + e = e || window.event; + return 'You may have unsaved changes.'; + }; + } }); diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 47d7955b..3dfd3421 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -11255,7 +11255,8 @@ define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', ' _setup_simple_zoom_buttons: _setup_simple_zoom_buttons, _setup_status: _setup_status, _setup_modes: _setup_modes, - _get_keys: _get_keys }; + _get_keys: _get_keys, + _setup_confirm_before_exit: _setup_confirm_before_exit }; return Builder; @@ -11280,6 +11281,7 @@ define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', ' css_path: null, css: null, starting_reaction: null, + never_ask_before_quit: false, // applied data auto_reaction_domain: true, reaction_data_path: null, @@ -11502,6 +11504,10 @@ define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', ' else this.view_mode(); + // confirm before leaving the page + if (this.options.enable_editing && !this.options.never_ask_before_quit) + this._setup_confirm_before_exit(); + // draw this.map.draw_everything(); } @@ -11952,6 +11958,18 @@ define('Builder',['utils', 'BuildInput', 'ZoomContainer', 'Map', 'CobraModel', ' } return keys; } + + function _setup_confirm_before_exit() { + /** Ask if the user wants to exit the page (to avoid unplanned refresh). + + */ + + window.onbeforeunload = function(e) { + // If we haven't been passed the event get the window.event + e = e || window.event; + return 'You may have unsaved changes.'; + }; + } }); define('DataMenu',["utils"], function(utils) { diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 72df8424..b85a2a6e 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,s,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,s,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sun, 7 Sep 2014 10:30:13 -0700 Subject: [PATCH 16/33] Parse URL in javascript for static site generator. --- escher/js/src/utils.js | 40 +++++++++++++- escher/lib/escher.1.0.0b3.js | 40 +++++++++++++- escher/lib/escher.1.0.0b3.min.js | 2 +- escher/plots.py | 95 +++++++++++++++++++------------- escher/static_site.py | 21 +++++++ escher/templates/content.html | 2 +- spec/javascripts/BuilderSpec.js | 6 +- spec/javascripts/utilsSpec.js | 15 +++++ 8 files changed, 176 insertions(+), 45 deletions(-) create mode 100644 escher/static_site.py diff --git a/escher/js/src/utils.js b/escher/js/src/utils.js index 64d874f0..90c3ab36 100644 --- a/escher/js/src/utils.js +++ b/escher/js/src/utils.js @@ -33,7 +33,8 @@ define(["lib/vkbeautify"], function(vkbeautify) { decompartmentalize: decompartmentalize, check_r: check_r, mean: mean, - check_for_parent_tag: check_for_parent_tag }; + check_for_parent_tag: check_for_parent_tag, + parse_url_components: parse_url_components }; // definitions function set_options(options, defaults) { @@ -612,4 +613,41 @@ define(["lib/vkbeautify"], function(vkbeautify) { } return false; } + + function parse_url_components(the_window, options) { + /** Parse the URL and return options based on the URL arguments. + + Arguments + --------- + + the_window: A reference to the global window. + + options: (optional) an existing options object to which new options + will be added. + + + Adapted from http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter + + */ + if (options===undefined) options = {}; + + var query = the_window.location.search.substring(1), + vars = query.split("&"); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split("="); + // If first entry with this name + if (typeof options[pair[0]] === "undefined") { + options[pair[0]] = pair[1]; + // If second entry with this name + } else if (typeof options[pair[0]] === "string") { + var arr = [ options[pair[0]], pair[1] ]; + options[pair[0]] = arr; + // If third or later entry with this name + } else { + options[pair[0]].push(pair[1]); + } + } + + return options; + } }); diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 3dfd3421..5a19bfa9 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -819,7 +819,8 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { decompartmentalize: decompartmentalize, check_r: check_r, mean: mean, - check_for_parent_tag: check_for_parent_tag }; + check_for_parent_tag: check_for_parent_tag, + parse_url_components: parse_url_components }; // definitions function set_options(options, defaults) { @@ -1398,6 +1399,43 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { } return false; } + + function parse_url_components(the_window, options) { + /** Parse the URL and return options based on the URL arguments. + + Arguments + --------- + + the_window: A reference to the global window. + + options: (optional) an existing options object to which new options + will be added. + + + Adapted from http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter + + */ + if (options===undefined) options = {}; + + var query = the_window.location.search.substring(1), + vars = query.split("&"); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split("="); + // If first entry with this name + if (typeof options[pair[0]] === "undefined") { + options[pair[0]] = pair[1]; + // If second entry with this name + } else if (typeof options[pair[0]] === "string") { + var arr = [ options[pair[0]], pair[1] ]; + options[pair[0]] = arr; + // If third or later entry with this name + } else { + options[pair[0]].push(pair[1]); + } + } + + return options; + } }); define('data_styles',["utils"], function(utils) { diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index b85a2a6e..76d45176 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}return{set_options:t,setup_svg:n,remove_child_nodes:r,load_css:i,load_files:u,load_the_file:o,make_class:a,setup_defs:f,draw_an_object:l,draw_a_nested_object:c,make_array:h,compare_arrays:p,array_to_object:d,clone:v,extend:m,unique_concat:g,object_slice_for_ids:y,c_plus_c:b,c_minus_c:w,c_times_scalar:E,download_json:S,load_json:x,export_svg:T,rotate_coords_recursive:N,rotate_coords:C,get_angle:k,to_degrees:L,angle_for_event:A,distance:O,check_undefined:M,compartmentalize:_,decompartmentalize:D,check_r:P,mean:H,check_for_parent_tag:B}}),n("data_styles",["utils"],function(e){function t(t,n,r){if(t===null)return null;t instanceof Array||(t=[t]);var i=function(){return t===null?null:t.length==1?null:t.length==2?null:console.warn("Bad data style: "+r)};return i(),t=e.array_to_object(t),t}function n(e,t,n){n===undefined&&(n=!1);if(e===null)return null;var r=null;e.length==1&&(r=e[0]);if(e.length==2){if(e[0]===null||e[1]===null)return null;r=e[1]-e[0]}return t.indexOf("abs")!=-1&&!n&&(r=Math.abs(r)),r}function r(e,t){return e===null?null:e.length==1?e[0]<=0:e.length==2?e[1]-e[0]<=0:!0}function i(e,t){function o(e,t){return e===null?"(nd)":t(e)}if(e===null)return o(null);var r=n(e,t,!0);if(e.length==1){var i=d3.format(".4g");return o(r,i)}if(e.length==2){var i=d3.format(".3g"),s=o(e[0],i);return s+=", "+o(e[1],i),s+=": "+o(r,i),s}return""}return{import_and_check:t,text_for_data:i,float_for_data:n,reverse_flux_for_data:r}}),n("draw",["utils","data_styles"],function(e,t){function n(e){e.on("mousedown.drag",null),e.on("touchstart.drag",null)}function r(t){e.check_undefined(arguments,["enter_selection"]),t.append("rect").attr("class","membrane")}function i(t){e.check_undefined(arguments,["enter_selection"]),t.attr("width",function(e){return e.width}).attr("height",function(e){return e.height}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).style("stroke-width",function(e){return 10}).attr("rx",function(e){return 20}).attr("ry",function(e){return 20})}function s(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return"r"+e.reaction_id}).attr("class","reaction").call(u);return}function o(t,n,r,i,s,o,u,c){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles","label_drag_behavior"]),t.select(".reaction-label").call(function(e){return a(e,s,u,c)}),e.draw_a_nested_object(t,".segment-group","segments","segment_id",f,function(e){return l(e,n,r,i,s,o,u)},function(e){e.remove()})}function u(t){e.check_undefined(arguments,["sel"]),t.append("text").attr("class","reaction-label label")}function a(t,r,i,s,o){e.check_undefined(arguments,["sel","has_reaction_data","reaction_data_styles","label_drag_behavior"]);var u=d3.format(".4g");t.text(function(e){var t=e.bigg_id;return r&&i.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(30)+"px"}).call(n).call(s)}function f(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("class","segment-group").attr("id",function(e){return"s"+e.segment_id});n.append("path").attr("class","segment"),n.append("g").attr("class","arrowheads")}function l(t,n,r,i,s,o,u){e.check_undefined(arguments,["update_selection","scale","drawn_nodes","defs","has_reaction_data","no_data_style","reaction_data_styles"]);var a=function(e,t){return e||t>0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t){t===undefined&&(t={});var n=e.location.search.substring(1),r=n.split("&");for(var i=0;i0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sun, 7 Sep 2014 14:45:14 -0700 Subject: [PATCH 17/33] Convert map_name & model_name to paths for static site. --- escher/js/src/utils.js | 18 +++++++++++++++++- escher/lib/escher.1.0.0b3.js | 18 +++++++++++++++++- escher/lib/escher.1.0.0b3.min.js | 2 +- escher/plots.py | 5 ++++- spec/javascripts/utilsSpec.js | 4 +++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/escher/js/src/utils.js b/escher/js/src/utils.js index 90c3ab36..fdd33b46 100644 --- a/escher/js/src/utils.js +++ b/escher/js/src/utils.js @@ -614,7 +614,7 @@ define(["lib/vkbeautify"], function(vkbeautify) { return false; } - function parse_url_components(the_window, options) { + function parse_url_components(the_window, options, map_download_url, model_download_url) { /** Parse the URL and return options based on the URL arguments. Arguments @@ -625,6 +625,11 @@ define(["lib/vkbeautify"], function(vkbeautify) { options: (optional) an existing options object to which new options will be added. + map_download_url: (optional) If map_name is in options, then add map_path + to options, with this url prepended. + + model_download_url: (optional) If model_name is in options, then add model_path + to options, with this url prepended. Adapted from http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter @@ -648,6 +653,17 @@ define(["lib/vkbeautify"], function(vkbeautify) { } } + // generate map_path and model_path + [ + [map_download_url, 'map_name'], + [model_download_url, 'model_name'] + ].forEach(function(ar) { + var url = ar[0], key = ar[1], + path = key.replace('name', 'path'); + if (url !== undefined && key in options) + options[path] = url + options[key] + '.json'; + }); + return options; } }); diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 5a19bfa9..6cfc0199 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1400,7 +1400,7 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { return false; } - function parse_url_components(the_window, options) { + function parse_url_components(the_window, options, map_download_url, model_download_url) { /** Parse the URL and return options based on the URL arguments. Arguments @@ -1411,6 +1411,11 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { options: (optional) an existing options object to which new options will be added. + map_download_url: (optional) If map_name is in options, then add map_path + to options, with this url prepended. + + model_download_url: (optional) If model_name is in options, then add model_path + to options, with this url prepended. Adapted from http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter @@ -1434,6 +1439,17 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { } } + // generate map_path and model_path + [ + [map_download_url, 'map_name'], + [model_download_url, 'model_name'] + ].forEach(function(ar) { + var url = ar[0], key = ar[1], + path = key.replace('name', 'path'); + if (url !== undefined && key in options) + options[path] = url + options[key] + '.json'; + }); + return options; } }); diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 76d45176..645ca677 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t){t===undefined&&(t={});var n=e.location.search.substring(1),r=n.split("&");for(var i=0;i0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n,r){t===undefined&&(t={});var i=e.location.search.substring(1),s=i.split("&");for(var o=0;o0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sun, 7 Sep 2014 14:49:40 -0700 Subject: [PATCH 18/33] Fix for urls --- escher/plots.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/escher/plots.py b/escher/plots.py index 94a83189..ca314fd9 100644 --- a/escher/plots.py +++ b/escher/plots.py @@ -326,9 +326,10 @@ def _draw_js(self, the_id, enable_editing, menu, enable_keys, dev, dev_str = '' if dev else 'escher.' # parse the url in javascript if js_url_parse: - o = u'options = %sutils.parse_url_components(window, options, %s, %s);\n' % (dev_str, - urls.map_download, - urls.model_download) + o = (u'options = %sutils.parse_url_components(window, ' + u'options, "%s", "%s");\n' % (dev_str, + urls.map_download, + urls.model_download)) draw = draw + o; # make the builder draw = draw + '%sBuilder(options);\n' % dev_str From f64b404b80d4daf0a8ba089ef21868d197d3b4e7 Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sun, 7 Sep 2014 16:57:51 -0700 Subject: [PATCH 19/33] fixed static cobra model call --- escher/js/src/utils.js | 7 +++---- escher/lib/escher.1.0.0b3.js | 7 +++---- escher/lib/escher.1.0.0b3.min.js | 2 +- spec/javascripts/utilsSpec.js | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/escher/js/src/utils.js b/escher/js/src/utils.js index fdd33b46..3b2e0581 100644 --- a/escher/js/src/utils.js +++ b/escher/js/src/utils.js @@ -655,11 +655,10 @@ define(["lib/vkbeautify"], function(vkbeautify) { // generate map_path and model_path [ - [map_download_url, 'map_name'], - [model_download_url, 'model_name'] + [map_download_url, 'map_name', 'map_path'], + [model_download_url, 'model_name', 'cobra_model_path'] ].forEach(function(ar) { - var url = ar[0], key = ar[1], - path = key.replace('name', 'path'); + var url = ar[0], key = ar[1], path = ar[2]; if (url !== undefined && key in options) options[path] = url + options[key] + '.json'; }); diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index 6cfc0199..b4677ae9 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1441,11 +1441,10 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { // generate map_path and model_path [ - [map_download_url, 'map_name'], - [model_download_url, 'model_name'] + [map_download_url, 'map_name', 'map_path'], + [model_download_url, 'model_name', 'cobra_model_path'] ].forEach(function(ar) { - var url = ar[0], key = ar[1], - path = key.replace('name', 'path'); + var url = ar[0], key = ar[1], path = ar[2]; if (url !== undefined && key in options) options[path] = url + options[key] + '.json'; }); diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 645ca677..c5e8381f 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n,r){t===undefined&&(t={});var i=e.location.search.substring(1),s=i.split("&");for(var o=0;o0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n,r){t===undefined&&(t={});var i=e.location.search.substring(1),s=i.split("&");for(var o=0;o0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sun, 7 Sep 2014 17:06:23 -0700 Subject: [PATCH 20/33] non-minified static files --- escher/static_site.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/escher/static_site.py b/escher/static_site.py index a35f6a06..b9ef72c7 100644 --- a/escher/static_site.py +++ b/escher/static_site.py @@ -7,15 +7,20 @@ def generate_static_site(): print build_path for kind in ['viewer', 'builder']: - js_source = 'web' - enable_editing = (kind=='builder') - - # make the builder - builder = Builder(safe=True) + for minified_js in [True, False]: + js_source = 'web' + enable_editing = (kind=='builder') - html = builder.save_html(filepath=join(build_path, kind+'.html'), - js_source=js_source, enable_editing=enable_editing, - js_url_parse=True) + # make the builder + builder = Builder(safe=True) + + filepath = join(build_path, + '%s%s.html' % (kind, '' if minified_js else '_not_minified')) + html = builder.save_html(filepath=filepath, + js_source=js_source, + minified_js=minified_js, + enable_editing=enable_editing, + js_url_parse=True) if __name__=='__main__': generate_static_site() From f3be4c23dc1ef0fd6b045530b83207741e16d5c0 Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sun, 7 Sep 2014 17:29:10 -0700 Subject: [PATCH 21/33] Correct use of setup.py; parse_url_components writes over existing options --- escher/js/src/utils.js | 14 +------ escher/lib/escher.1.0.0b3.js | 14 +------ escher/lib/escher.1.0.0b3.min.js | 2 +- setup.py | 65 +++++++++++++++++++++++--------- spec/javascripts/utilsSpec.js | 3 +- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/escher/js/src/utils.js b/escher/js/src/utils.js index 3b2e0581..e8f876d2 100644 --- a/escher/js/src/utils.js +++ b/escher/js/src/utils.js @@ -623,7 +623,7 @@ define(["lib/vkbeautify"], function(vkbeautify) { the_window: A reference to the global window. options: (optional) an existing options object to which new options - will be added. + will be added. Overwrites existing arguments in options. map_download_url: (optional) If map_name is in options, then add map_path to options, with this url prepended. @@ -640,17 +640,7 @@ define(["lib/vkbeautify"], function(vkbeautify) { vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); - // If first entry with this name - if (typeof options[pair[0]] === "undefined") { - options[pair[0]] = pair[1]; - // If second entry with this name - } else if (typeof options[pair[0]] === "string") { - var arr = [ options[pair[0]], pair[1] ]; - options[pair[0]] = arr; - // If third or later entry with this name - } else { - options[pair[0]].push(pair[1]); - } + options[pair[0]] = pair[1]; } // generate map_path and model_path diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index b4677ae9..aa5dc529 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -1409,7 +1409,7 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { the_window: A reference to the global window. options: (optional) an existing options object to which new options - will be added. + will be added. Overwrites existing arguments in options. map_download_url: (optional) If map_name is in options, then add map_path to options, with this url prepended. @@ -1426,17 +1426,7 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); - // If first entry with this name - if (typeof options[pair[0]] === "undefined") { - options[pair[0]] = pair[1]; - // If second entry with this name - } else if (typeof options[pair[0]] === "string") { - var arr = [ options[pair[0]], pair[1] ]; - options[pair[0]] = arr; - // If third or later entry with this name - } else { - options[pair[0]].push(pair[1]); - } + options[pair[0]] = pair[1]; } // generate map_path and model_path diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index c5e8381f..299520c4 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n,r){t===undefined&&(t={});var i=e.location.search.substring(1),s=i.split("&");for(var o=0;o0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n,r){t===undefined&&(t={});var i=e.location.search.substring(1),s=i.split("&");for(var o=0;o0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase() Date: Sun, 7 Sep 2014 19:10:29 -0700 Subject: [PATCH 22/33] Generate static site index file. --- .gitignore | 7 +++- escher/generate_index.py | 15 ++++++++ escher/js/web/index.js | 33 ++++++++++++++++++ escher/js/web/index_gh_pages.js | 21 ++++++++++++ escher/server.py | 17 +++++++-- escher/static_site.py | 15 +++++++- escher/templates/index.html | 61 ++++++++++----------------------- maps/v1/README | 1 + maps/v1/index.json | 1 + models/v1/README | 1 + models/v1/index.json | 1 + 11 files changed, 126 insertions(+), 47 deletions(-) create mode 100644 escher/generate_index.py create mode 100644 escher/js/web/index.js create mode 100644 escher/js/web/index_gh_pages.js create mode 100644 maps/v1/README create mode 100644 maps/v1/index.json create mode 100644 models/v1/README create mode 100644 models/v1/index.json diff --git a/.gitignore b/.gitignore index 4ed54d97..8de17038 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,9 @@ Escher.egg-info/ .ipynb_checkpoints/ build/* env/* -envset/* \ No newline at end of file +envset/* +builder.html +builder_not_minified.html +viewer.html +viewer_not_minified.html +index.html \ No newline at end of file diff --git a/escher/generate_index.py b/escher/generate_index.py new file mode 100644 index 00000000..5ecd9893 --- /dev/null +++ b/escher/generate_index.py @@ -0,0 +1,15 @@ +import json +from os import listdir +from os.path import join, dirname, realpath + +directory = realpath(dirname(realpath(__file__)), '..') + +index_directories = ['maps/v1', 'models/v1'] + +for index_dir in index_directories: + index = [] + for filename in listdir(join(directory, index_dir)): + if filename.endswith('.json'): + index.append(filename.replace('.json', '')) + with open(join(directory, index_dir, 'index.json'), 'w') as f: + json.dump(index, f) diff --git a/escher/js/web/index.js b/escher/js/web/index.js new file mode 100644 index 00000000..98baf676 --- /dev/null +++ b/escher/js/web/index.js @@ -0,0 +1,33 @@ +function get_value(id) { + var a = document.getElementById(id); + return a.options[a.selectedIndex].value; +} + +function submit() { + var map_value = get_value('map'), + model_value = get_value('model'), + options_value = get_value('options'), + add = [], + url; + if (model_value!='none') + add.push('model_name=' + model_value); + if (map_value!='none') + add.push('map_name=' + map_value); + + if (options_value=='local_viewer') { + url = 'local/viewer.html'; + } else if (options_value=='local_builder') { + url = 'local/builder.html'; + } else if (options_value=='viewer') { + url = 'viewer.html'; + } else { + url = 'builder.html'; + } + + url += '?'; + for (var i=0, l=add.length; i < l; i++) { + if (i > 0) url += '&'; + url += add[i]; + } + window.location.href = url; +} diff --git a/escher/js/web/index_gh_pages.js b/escher/js/web/index_gh_pages.js new file mode 100644 index 00000000..60ec9f10 --- /dev/null +++ b/escher/js/web/index_gh_pages.js @@ -0,0 +1,21 @@ +// get the models +$.getJSON('models/v1/index.json', function(data) { + var sel = $('#model'); + data.forEach(function(model_loc) { + sel.append($('
- + + {% if web_version %} + + {% endif %} {% endblock %} diff --git a/maps/v1/README b/maps/v1/README new file mode 100644 index 00000000..7d5605bd --- /dev/null +++ b/maps/v1/README @@ -0,0 +1 @@ +This is here strictly for testing the static site. \ No newline at end of file diff --git a/maps/v1/index.json b/maps/v1/index.json new file mode 100644 index 00000000..a0d06975 --- /dev/null +++ b/maps/v1/index.json @@ -0,0 +1 @@ +["iJO1366_central_metabolism", "iJO1366_fatty_acid_metabolism"] \ No newline at end of file diff --git a/models/v1/README b/models/v1/README new file mode 100644 index 00000000..7d5605bd --- /dev/null +++ b/models/v1/README @@ -0,0 +1 @@ +This is here strictly for testing the static site. \ No newline at end of file diff --git a/models/v1/index.json b/models/v1/index.json new file mode 100644 index 00000000..fe6460bf --- /dev/null +++ b/models/v1/index.json @@ -0,0 +1 @@ +["iJO1366", "iJO1366_heterologous", "iMM904", "RECON1"] \ No newline at end of file From 8802b5249325559543835f5fb35a4e4254acbcbb Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sun, 7 Sep 2014 19:12:56 -0700 Subject: [PATCH 23/33] fixed error --- escher/generate_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escher/generate_index.py b/escher/generate_index.py index 5ecd9893..412bb367 100644 --- a/escher/generate_index.py +++ b/escher/generate_index.py @@ -2,14 +2,14 @@ from os import listdir from os.path import join, dirname, realpath -directory = realpath(dirname(realpath(__file__)), '..') +directory = realpath(join(dirname(realpath(__file__)), '..')) index_directories = ['maps/v1', 'models/v1'] for index_dir in index_directories: index = [] for filename in listdir(join(directory, index_dir)): - if filename.endswith('.json'): + if filename.endswith('.json') and filename not in ['index.json', 'README']: index.append(filename.replace('.json', '')) with open(join(directory, index_dir, 'index.json'), 'w') as f: json.dump(index, f) From cf5cdbd6469fe50d511faff8ea104bc46d1c5d45 Mon Sep 17 00:00:00 2001 From: Zachary King Date: Sun, 7 Sep 2014 21:16:05 -0700 Subject: [PATCH 24/33] Fixed urls for static site --- escher/js/web/index.js | 2 +- escher/plots.py | 14 ++++++++------ escher/server.py | 11 ++++++++++- escher/static_site.py | 14 ++++++++++++-- escher/templates/content.html | 2 +- escher/templates/index.html | 19 ++++++++++--------- escher/tests/test_urls.py | 2 +- escher/urls.py | 29 +++++++++++++++++++---------- 8 files changed, 62 insertions(+), 31 deletions(-) diff --git a/escher/js/web/index.js b/escher/js/web/index.js index 98baf676..c467e0e6 100644 --- a/escher/js/web/index.js +++ b/escher/js/web/index.js @@ -29,5 +29,5 @@ function submit() { if (i > 0) url += '&'; url += add[i]; } - window.location.href = url; + window.location.href = url; // TODO https here } diff --git a/escher/plots.py b/escher/plots.py index ca314fd9..cba4e68d 100644 --- a/escher/plots.py +++ b/escher/plots.py @@ -328,8 +328,8 @@ def _draw_js(self, the_id, enable_editing, menu, enable_keys, dev, if js_url_parse: o = (u'options = %sutils.parse_url_components(window, ' u'options, "%s", "%s");\n' % (dev_str, - urls.map_download, - urls.model_download)) + urls.map_download_local, + urls.model_download_local)) draw = draw + o; # make the builder draw = draw + '%sBuilder(options);\n' % dev_str @@ -381,8 +381,9 @@ def _get_html(self, js_source='web', menu='none', scroll_behavior='pan', leave the page. By default, this message is displayed if enable_editing is True. - js_url_parse: Use javascript to parse the URL options. Primarily used - for generating static pages (see static_site.py). + js_url_parse: Use javascript to parse the URL options. Used for + generating static pages (see static_site.py), and only works if maps and + models are available locally. """ @@ -586,8 +587,9 @@ def save_html(self, filepath=None, js_source='web', menu='all', scroll_behavior= leave the page. By default, this message is displayed if enable_editing is True. - js_url_parse: Use javascript to parse the URL options. Primarily used - for generating static pages (see static_site.py). + js_url_parse: Use javascript to parse the URL options. Used for + generating static pages (see static_site.py), and only works if maps and + models are available locally. """ html = self._get_html(js_source=js_source, menu=menu, scroll_behavior=scroll_behavior, diff --git a/escher/server.py b/escher/server.py index 76a2639c..2e157ff6 100644 --- a/escher/server.py +++ b/escher/server.py @@ -71,9 +71,18 @@ def get(self): join(urls.map_download, 'index.json')) maps = json.loads(response.body) template = env.get_template('index.html') - data = template.render(models=models, + + data = template.render(jquery=urls.jquery_local, + boot_css=urls.boot_css_local, + index_css=urls.index_css_local, + logo=urls.logo_local, + github=urls.github, + index_js=urls.index_js_local, + index_gh_pages_js=urls.index_gh_pages_js_local, + models=models, maps=maps, web_version=False) + self.set_header("Content-Type", "text/html") self.serve(data) diff --git a/escher/static_site.py b/escher/static_site.py index fe8d9b9f..dabfb160 100644 --- a/escher/static_site.py +++ b/escher/static_site.py @@ -1,4 +1,5 @@ from escher.plots import Builder +from escher import urls from os.path import join, dirname, realpath from jinja2 import Environment, PackageLoader @@ -8,13 +9,22 @@ def generate_static_site(): build_path = realpath(join(dirname(realpath(__file__)), '..')) - print build_path + print 'Generating static site at %s' % build_path # index file template = env.get_template('index.html') - data = template.render(models=[], + + data = template.render(jquery=urls.jquery_local, + boot_css=urls.boot_css_local, + index_css=urls.index_css_local, + logo=urls.logo_local, + github=urls.github, + index_js=urls.index_js_local, + index_gh_pages_js=urls.index_gh_pages_js_local, + models=[], maps=[], web_version=True) + with open(join(build_path, 'index.html'), 'w') as f: f.write(data) diff --git a/escher/templates/content.html b/escher/templates/content.html index a1c3449c..284a3adb 100644 --- a/escher/templates/content.html +++ b/escher/templates/content.html @@ -5,7 +5,7 @@ - + {% endblock %} diff --git a/escher/templates/index.html b/escher/templates/index.html index 63d2fd0f..6ea6bffc 100644 --- a/escher/templates/index.html +++ b/escher/templates/index.html @@ -1,19 +1,20 @@ {% extends "standalone.html" %} {% block title %}Escher{% endblock %} {% block head %} - - - - + + + + - + + {% endblock %} {% block content %}
- +

ESCHER

@@ -73,13 +74,13 @@

FAQ

- + {% if web_version %} - + {% endif %} {% endblock %} diff --git a/escher/tests/test_urls.py b/escher/tests/test_urls.py index 4c01cc2a..6264523f 100644 --- a/escher/tests/test_urls.py +++ b/escher/tests/test_urls.py @@ -16,4 +16,4 @@ def make_http(url): # local for u in [urls.d3_local, urls.escher_local, urls.escher_min_local]: - assert exists(join(directory, u)) + assert exists(join(directory, '..', u)) diff --git a/escher/urls.py b/escher/urls.py index ee295827..f0d7e2ab 100644 --- a/escher/urls.py +++ b/escher/urls.py @@ -1,26 +1,35 @@ from version import __version__ map_download = "https://zakandrewking.github.io/escher/maps/v1/" +map_download_local = "maps/v1/" model_download = "https://zakandrewking.github.io/escher/models/v1/" +model_download_local = "models/v1/" + escher_home = "https://zakandrewking.github.io/escher/" +github = "https://github.com/zakandrewking/escher" +logo_local = "escher/resources/escher-logo@2x.png" builder_embed_css = "https://zakandrewking.github.io/escher/escher/css/builder-embed.css" -builder_embed_css_local = "css/builder-embed.css" +builder_embed_css_local = "escher/css/builder-embed.css" builder_css = "https://zakandrewking.github.io/escher/escher/css/builder.css" -builder_css_local = "css/builder.css" +builder_css_local = "escher/css/builder.css" d3 = "//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min.js" -d3_local = "lib/d3.min.js" +d3_local = "escher/lib/d3.min.js" escher = "https://zakandrewking.github.io/escher/escher.%s.js" % __version__ escher_min = "https://zakandrewking.github.io/escher/escher.%s.min.js" % __version__ -escher_local = "lib/escher.%s.js" % __version__ -escher_min_local = "lib/escher.%s.min.js" % __version__ +escher_local = "escher/lib/escher.%s.js" % __version__ +escher_min_local = "escher/lib/escher.%s.min.js" % __version__ boot_js = "//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js" -boot_js_local = "lib/bootstrap-3.1.1.min.js" +boot_js_local = "escher/lib/bootstrap-3.1.1.min.js" boot_css = "//netdna.bootstrapcdn.com/bootswatch/3.1.1/simplex/bootstrap.min.css" -boot_css_local = "lib/bootstrap-3.1.1.min.css" +boot_css_local = "escher/lib/bootstrap-3.1.1.min.css" jquery = "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js" -jquery_local = "lib/jquery-2.1.0.min.js" +jquery_local = "escher/lib/jquery-2.1.0.min.js" require_js = "//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.11/require.min.js" -require_js_local = "lib/require.min.js" +require_js_local = "escher/lib/require.min.js" bacon = "//cdnjs.cloudflare.com/ajax/libs/bacon.js/0.7.12/bacon.min.js" -bacon_local = "lib/bacon-0.7.12.min.js" +bacon_local = "escher/lib/bacon-0.7.12.min.js" + +index_js_local = "escher/js/web/index.js" +index_gh_pages_js_local = "escher/js/web/index_gh_pages.js" +index_css_local = "escher/css/index.css" From 95c057ad53f809e4c2b142359c71831170b045d0 Mon Sep 17 00:00:00 2001 From: Zak King Date: Mon, 8 Sep 2014 18:29:42 -0700 Subject: [PATCH 25/33] new homepage with options & organism --- escher/js/web/index.js | 143 +++++++++++++++++++++++++++++--- escher/js/web/index_gh_pages.js | 22 +---- escher/plots.py | 34 ++++++-- escher/server.py | 20 ++--- escher/static_site.py | 5 +- escher/templates/index.html | 50 ++++++----- escher/tests/test_plots.py | 20 +++-- escher/urls.py | 4 + index.json | 1 + maps/v1/README | 1 - maps/v1/index.json | 1 - models/v1/README | 1 - models/v1/index.json | 1 - setup.py | 4 +- 14 files changed, 224 insertions(+), 83 deletions(-) create mode 100644 index.json delete mode 100644 maps/v1/README delete mode 100644 maps/v1/index.json delete mode 100644 models/v1/README delete mode 100644 models/v1/index.json diff --git a/escher/js/web/index.js b/escher/js/web/index.js index c467e0e6..5ae24a1a 100644 --- a/escher/js/web/index.js +++ b/escher/js/web/index.js @@ -1,18 +1,27 @@ -function get_value(id) { - var a = document.getElementById(id); - return a.options[a.selectedIndex].value; +function convert_model_id(model_id) { + var parts = model_id.split('/'); + return parts[1] + ':' + parts[3]; +} +function convert_map_id(map_id) { + var parts = map_id.split('/'); + return parts[1] + ':' + parts[3] + ':' + parts[5]; } - function submit() { - var map_value = get_value('map'), - model_value = get_value('model'), - options_value = get_value('options'), + var map_value = d3.select('#maps').node().value, + model_value = d3.select('#models').node().value, + options_value = d3.select('#tools').node().value, + scroll_value = d3.select('#scroll').node().checked, + never_ask_value = d3.select('#never_ask').node().checked, add = [], url; if (model_value!='none') - add.push('model_name=' + model_value); + add.push('model_name=' + convert_model_id(model_value)); if (map_value!='none') - add.push('map_name=' + map_value); + add.push('map_name=' + convert_map_id(map_value)); + if (scroll_value) + add.push('scroll_behavior=zoom'); + if (never_ask_value) + add.push('never_ask_before_quit=true'); if (options_value=='local_viewer') { url = 'local/viewer.html'; @@ -29,5 +38,119 @@ function submit() { if (i > 0) url += '&'; url += add[i]; } - window.location.href = url; // TODO https here + window.location.href = url; +} + +function draw_models_select(data) { + /** Draw the models selector. + + */ + var filter_models = function(model_id) { + var org = d3.select('#organisms').node().value; + if (org=='all') + return true; + if (org.split('/')[1]==model_id.split('/').slice(-3)[0]) + return true; + return false; + }; + + var model_data = data.models.filter(filter_models), + models_select = d3.select('#models'), + models = models_select.selectAll('.model') + .data(model_data); + models.enter() + .append('option') + .classed('model', true) + .attr('value', function(d) { return d; }) + .text(function(d) { + var model = d.split('/').slice(-1)[0]; + return model; + }); + models.exit().remove(); +} +function draw_maps_select(data) { /** Draw the models selector. + + */ + var filter_maps = function(map_id) { + var org = d3.select('#organisms').node().value; + if (org=='all') + return true; + if (org.split('/')[1]==map_id.split('/').slice(-5)[0]) + return true; + return false; + }; + + var map_data = data.maps.filter(filter_maps), + maps_select = d3.select('#maps'), + maps = maps_select.selectAll('.map') + .data(map_data); + maps.enter() + .append('option') + .classed('map', true) + .attr('value', function(d) { return d; }) + .text(function(d) { + var map = d.split('/').slice(-1)[0], + model = d.split('/').slice(-3)[0]; + return map + ' (' + model + ')'; + }); + maps.exit().remove(); + + var n = maps_select.node(); + if (map_data.length > 0 && n.selectedIndex==0) + n.selectedIndex = 1; +} +function draw_organisms_select(data) { + var org = d3.select('#organisms').selectAll('.organism') + .data(data.organisms); + org.enter() + .append('option') + .classed('organism', true) + .attr('value', function(d) { return d; }) + .text(function(d) { + var parts = d.split('/').slice(-1)[0].split('_'); + return parts[0].toUpperCase() + '. ' + parts[1]; + }); +} + +function setup() { + // GO + draw_organisms_select(data); + draw_models_select(data); + draw_maps_select(data); + + // update filters + d3.select('#organisms') + .on('change', function() { + draw_models_select(data); + draw_maps_select(data); + }); + + // make it a builder with a model, and vice-versa + d3.select('#models') + .on('change', function() { + var is_none = this.value == 'none'; + d3.select('#tools').selectAll('.tool') + .attr('disabled', function() { + if (is_none || this.value.indexOf('viewer')==-1) + return null; + return true; + }); + // make sure a disabled option is not selected + var n = d3.select('#tools').node(); + if (!is_none && n.value.indexOf('viewer')!=-1) { + n.selectedIndex = n.selectedIndex + 1; + } + }); + + // submit button + d3.select('#submit').on('click', submit); + + // submit on enter + var selection = d3.select(window), + kc = 13; + selection.on('keydown.'+kc, function() { + if (d3.event.keyCode==kc) { + submit(); + } + }); } diff --git a/escher/js/web/index_gh_pages.js b/escher/js/web/index_gh_pages.js index 60ec9f10..874845d8 100644 --- a/escher/js/web/index_gh_pages.js +++ b/escher/js/web/index_gh_pages.js @@ -1,21 +1,5 @@ // get the models -$.getJSON('models/v1/index.json', function(data) { - var sel = $('#model'); - data.forEach(function(model_loc) { - sel.append($('
+
+
+

Filter by organism

+ +
+

Model

- - {% for model in models %} - - {% endfor %}
-
+

Map

- - {% for map in maps %} - - {% endfor %}
-

Options

- + + {% if not web_version %} - - + + {% endif %}
-
-
+
+
+

Options

+
Scroll to zoom (instead scroll to pan)
+
Never ask before reloading
+
+
+
@@ -79,8 +88,11 @@

FAQ

- + {% if web_version %} + {% else %} + {% endif %} + {% endblock %} diff --git a/escher/tests/test_plots.py b/escher/tests/test_plots.py index 4b32c4ca..9fdfa44a 100644 --- a/escher/tests/test_plots.py +++ b/escher/tests/test_plots.py @@ -1,7 +1,7 @@ import escher.server from escher import (Builder, get_cache_dir, clear_cache, list_cached_maps, list_cached_models) -from escher.plots import load_resource +from escher.plots import (load_resource, model_name_to_url, map_name_to_url) import os from os.path import join @@ -31,14 +31,22 @@ def test_get_cache_dir(): # clear_cache() # Builder(model_name='iJO1366') # assert list_cached_models() == ['iJO1366'] - + +def test_model_name_to_url(): + url = model_name_to_url('e_coli:iJO1366') + assert url == 'https://zakandrewking.github.io/escher/organisms/e_coli/models/iJO1366.json' + +def test_map_name_to_url(): + url = map_name_to_url('e_coli:iJO1366:central_metabolism') + assert url == 'https://zakandrewking.github.io/escher/organisms/e_coli/models/iJO1366/maps/central_metabolism.json' + def test_load_resource(tmpdir): assert load_resource('{"r": "val"}', 'name') == '{"r": "val"}' directory = os.path.abspath(os.path.dirname(__file__)) assert load_resource(join(directory, 'example.json'), 'name').strip() == '{"r": "val"}' - url = "https://zakandrewking.github.io/escher/maps/v1/iJO1366_central_metabolism.json" + url = "https://zakandrewking.github.io/escher/organisms/e_coli/models/iJO1366/maps/central_metabolism.json" _ = json.loads(load_resource(url, 'name')) # with raises(URLError): @@ -79,15 +87,15 @@ def test_Builder(tmpdir): b._get_html(scroll_behavior='zoom') # download - b = Builder(map_name='iJO1366_central_metabolism', model_name='iJO1366') + b = Builder(map_name='e_coli:iJO1366:central_metabolism', model_name='e_coli:iJO1366') assert b.loaded_map_json is not None assert b.loaded_model_json is not None b.display_in_notebook(height=200) # data - b = Builder(map_name='iJO1366_central_metabolism', model_name='iJO1366', + b = Builder(map_name='e_coli:iJO1366:central_metabolism', model_name='e_coli:iJO1366', reaction_data=[{'GAPD': 123}, {'GAPD': 123}]) - b = Builder(map_name='iJO1366_central_metabolism', model_name='iJO1366', + b = Builder(map_name='e_coli:iJO1366:central_metabolism', model_name='e_coli:iJO1366', metabolite_data=[{'nadh_c': 123}, {'nadh_c': 123}]) assert type(b.the_id) is unicode diff --git a/escher/urls.py b/escher/urls.py index f0d7e2ab..c98e9aed 100644 --- a/escher/urls.py +++ b/escher/urls.py @@ -4,6 +4,10 @@ map_download_local = "maps/v1/" model_download = "https://zakandrewking.github.io/escher/models/v1/" model_download_local = "models/v1/" +organism_download = "https://zakandrewking.github.io/escher/organisms/" +organism_download_local = "organisms/" +download = "https://zakandrewking.github.io/escher/" +download_local = "/" escher_home = "https://zakandrewking.github.io/escher/" github = "https://github.com/zakandrewking/escher" diff --git a/index.json b/index.json new file mode 100644 index 00000000..05d54611 --- /dev/null +++ b/index.json @@ -0,0 +1 @@ +{"models": ["organisms/e_coli/models/iJO1366"], "maps": ["organisms/e_coli/models/iJO1366/maps/central_metabolism", "organisms/e_coli/models/iJO1366/maps/fatty_acid_metabolism"], "organisms": ["organisms/e_coli", "organisms/h_sapiens", "organisms/s_cerevisiae"]} \ No newline at end of file diff --git a/maps/v1/README b/maps/v1/README deleted file mode 100644 index 7d5605bd..00000000 --- a/maps/v1/README +++ /dev/null @@ -1 +0,0 @@ -This is here strictly for testing the static site. \ No newline at end of file diff --git a/maps/v1/index.json b/maps/v1/index.json deleted file mode 100644 index a0d06975..00000000 --- a/maps/v1/index.json +++ /dev/null @@ -1 +0,0 @@ -["iJO1366_central_metabolism", "iJO1366_fatty_acid_metabolism"] \ No newline at end of file diff --git a/models/v1/README b/models/v1/README deleted file mode 100644 index 7d5605bd..00000000 --- a/models/v1/README +++ /dev/null @@ -1 +0,0 @@ -This is here strictly for testing the static site. \ No newline at end of file diff --git a/models/v1/index.json b/models/v1/index.json deleted file mode 100644 index fe6460bf..00000000 --- a/models/v1/index.json +++ /dev/null @@ -1 +0,0 @@ -["iJO1366", "iJO1366_heterologous", "iMM904", "RECON1"] \ No newline at end of file diff --git a/setup.py b/setup.py index babe25f1..41821128 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def run(self): os.remove(f) print 'done cleaning' -class BuildCommand(Command): +class JSBuildCommand(Command): description = "Custom build command that generates escher lib files" user_options = [] def initialize_options(self): @@ -69,5 +69,5 @@ def run(self): 'lib/*.js', 'lib/*.css', 'lib/fonts/*', 'resources/*']}, cmdclass={'clean': CleanCommand, - 'build': BuildCommand, + 'buildjs': JSBuildCommand, 'test': TestCommand}) From 7fe79c73fff974525d1186dd8b33119f70aca89a Mon Sep 17 00:00:00 2001 From: Zachary King Date: Mon, 8 Sep 2014 19:48:49 -0700 Subject: [PATCH 26/33] Fixed url handling on static site --- escher/js/src/utils.js | 44 +++++++++++++++++++++++++++----- escher/lib/escher.1.0.0b3.js | 44 +++++++++++++++++++++++++++----- escher/lib/escher.1.0.0b3.min.js | 2 +- escher/plots.py | 5 ++-- escher/templates/index.html | 15 ++++++----- escher/urls.py | 2 +- spec/javascripts/utilsSpec.js | 24 +++++++++++------ 7 files changed, 104 insertions(+), 32 deletions(-) diff --git a/escher/js/src/utils.js b/escher/js/src/utils.js index e8f876d2..6e84114b 100644 --- a/escher/js/src/utils.js +++ b/escher/js/src/utils.js @@ -34,6 +34,7 @@ define(["lib/vkbeautify"], function(vkbeautify) { check_r: check_r, mean: mean, check_for_parent_tag: check_for_parent_tag, + name_to_url: name_to_url, parse_url_components: parse_url_components }; // definitions @@ -614,7 +615,38 @@ define(["lib/vkbeautify"], function(vkbeautify) { return false; } - function parse_url_components(the_window, options, map_download_url, model_download_url) { + function name_to_url(name, download_url, type) { + /** Convert short name to url. + + Arguments + --------- + + name: The short name, e.g. e_coli:iJO1366:central_metabolism. + + download_url: The url to prepend. + + type: Either 'model' or 'map'. + + */ + // strip download_url + download_url = download_url.replace(/^\/|\/$/g, ''); + + var parts = name.split(':'), + longname; + if (['model', 'map'].indexOf(type) == -1) + throw Error('Bad type: ' + type); + if (parts.length != (type=='model' ? 2 : 3)) + throw Error('Bad ' + type + ' name'); + if (type=='model') + longname = ['organisms', parts[0], 'models', parts[1]+'.json'].join('/'); + else + longname = ['organisms', parts[0], 'models', parts[1], 'maps', parts[2]+'.json'].join('/'); + var out = [download_url, longname].join('/'); + // strip final path + return out.replace(/^\/|\/$/g, ''); + } + + function parse_url_components(the_window, options, download_url) { /** Parse the URL and return options based on the URL arguments. Arguments @@ -645,12 +677,12 @@ define(["lib/vkbeautify"], function(vkbeautify) { // generate map_path and model_path [ - [map_download_url, 'map_name', 'map_path'], - [model_download_url, 'model_name', 'cobra_model_path'] + ['map', 'map_name', 'map_path'], + ['model', 'model_name', 'cobra_model_path'] ].forEach(function(ar) { - var url = ar[0], key = ar[1], path = ar[2]; - if (url !== undefined && key in options) - options[path] = url + options[key] + '.json'; + var type = ar[0], key = ar[1], path = ar[2]; + if (download_url!==undefined && key in options) + options[path] = name_to_url(options[key], download_url, type); }); return options; diff --git a/escher/lib/escher.1.0.0b3.js b/escher/lib/escher.1.0.0b3.js index aa5dc529..7f3cca6a 100644 --- a/escher/lib/escher.1.0.0b3.js +++ b/escher/lib/escher.1.0.0b3.js @@ -820,6 +820,7 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { check_r: check_r, mean: mean, check_for_parent_tag: check_for_parent_tag, + name_to_url: name_to_url, parse_url_components: parse_url_components }; // definitions @@ -1400,7 +1401,38 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { return false; } - function parse_url_components(the_window, options, map_download_url, model_download_url) { + function name_to_url(name, download_url, type) { + /** Convert short name to url. + + Arguments + --------- + + name: The short name, e.g. e_coli:iJO1366:central_metabolism. + + download_url: The url to prepend. + + type: Either 'model' or 'map'. + + */ + // strip download_url + download_url = download_url.replace(/^\/|\/$/g, ''); + + var parts = name.split(':'), + longname; + if (['model', 'map'].indexOf(type) == -1) + throw Error('Bad type: ' + type); + if (parts.length != (type=='model' ? 2 : 3)) + throw Error('Bad ' + type + ' name'); + if (type=='model') + longname = ['organisms', parts[0], 'models', parts[1]+'.json'].join('/'); + else + longname = ['organisms', parts[0], 'models', parts[1], 'maps', parts[2]+'.json'].join('/'); + var out = [download_url, longname].join('/'); + // strip final path + return out.replace(/^\/|\/$/g, ''); + } + + function parse_url_components(the_window, options, download_url) { /** Parse the URL and return options based on the URL arguments. Arguments @@ -1431,12 +1463,12 @@ define('utils',["lib/vkbeautify"], function(vkbeautify) { // generate map_path and model_path [ - [map_download_url, 'map_name', 'map_path'], - [model_download_url, 'model_name', 'cobra_model_path'] + ['map', 'map_name', 'map_path'], + ['model', 'model_name', 'cobra_model_path'] ].forEach(function(ar) { - var url = ar[0], key = ar[1], path = ar[2]; - if (url !== undefined && key in options) - options[path] = url + options[key] + '.json'; + var type = ar[0], key = ar[1], path = ar[2]; + if (download_url!==undefined && key in options) + options[path] = name_to_url(options[key], download_url, type); }); return options; diff --git a/escher/lib/escher.1.0.0b3.min.js b/escher/lib/escher.1.0.0b3.min.js index 299520c4..0c1188df 100644 --- a/escher/lib/escher.1.0.0b3.min.js +++ b/escher/lib/escher.1.0.0b3.min.js @@ -60,4 +60,4 @@ * **/ -(function(e,t){typeof define=="function"&&define.amd?define("escher",t):e.escher=t()})(this,function(){var e,t,n;return function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n,r){t===undefined&&(t={});var i=e.location.search.substring(1),s=i.split("&");for(var o=0;o0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v\s{0,}<").replace(/-1){u+=f[o]+r[a],s=!0;if(r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1||r[a].search(/!DOCTYPE/)>-1)s=!1}else r[a].search(/-->/)>-1||r[a].search(/\]>/)>-1?(u+=r[a],s=!1):/^<\w/.exec(r[a-1])&&/^<\/\w/.exec(r[a])&&/^<[\w:\-\.\,]+/.exec(r[a-1])==/^<\/[\w:\-\.\,]+/.exec(r[a])[0].replace("/","")?(u+=r[a],s||o--):r[a].search(/<\w/)>-1&&r[a].search(/<\//)==-1&&r[a].search(/\/>/)==-1?u=s?u+=r[a]:u+=f[o++]+r[a]:r[a].search(/<\w/)>-1&&r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\//)>-1?u=s?u+=r[a]:u+=f[--o]+r[a]:r[a].search(/\/>/)>-1?u=s?u+=r[a]:u+=f[o]+r[a]:r[a].search(/<\?/)>-1?u+=f[o]+r[a]:r[a].search(/xmlns\:/)>-1||r[a].search(/xmlns\=/)>-1?u+=f[o]+r[a]:u+=r[a];return u[0]=="\n"?u.slice(1):u},t.prototype.json=function(e,t){var t=t?t:this.step;return typeof JSON=="undefined"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,t):typeof e=="object"?JSON.stringify(e,null,t):e},t.prototype.css=function(t,n){var r=t.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=r.length,s=0,o="",u=0,a=n?e(n):this.shift;for(u=0;u/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return n.replace(/>\s{0,}<")},t.prototype.jsonmin=function(e){return typeof JSON=="undefined"?e:JSON.stringify(JSON.parse(e),null,0)},t.prototype.cssmin=function(e,t){var n=t?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return n.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")},t.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")},new t}),n("utils",["lib/vkbeautify"],function(e){function t(e,t){if(e===undefined)return t;var n=-1,r=t;for(var i in e){var s=e[i];s===undefined&&(s=null),r[i]=s}return r}function n(e,t,n){var r=function(e,t){e&&(d3.select("body").classed("fill-screen-body",!0),t.classed("fill-screen-div",!0));var n=t.append("svg").attr("class","escher-svg").attr("xmlns","http://www.w3.org/2000/svg");return n},i;e.classed("escher-container",!0);if(t)return e;if(e)return r(n,e);throw new Error("No selection")}function r(e){var t=e.node();while(t.hasChildNodes())t.removeChild(t.lastChild)}function i(e,t){var n="";return e&&d3.text(e,function(e,r){e&&console.warn(e),n=r,t(n)}),!1}function s(){return"omg yes"}function o(e,t,n,r){function i(e,t){return e.indexOf(t,e.length-t.length)!==-1}if(r){t&&console.warn("File "+t+" overridden by value."),n.call(e,null,r,t);return}if(!t){n.call(e,"No filename",null,t);return}i(t,"json")?d3.json(t,function(e,r){n(e,r,t)}):i(t,"css")?d3.text(t,function(e,r){n(e,r,t)}):n.call(e,"Unrecognized file type",null,t);return}function u(e,t,n){var r=-1,i=t.length,s={};while(++r\n \n'+s,i.setAttribute("href-lang","image/svg+xml"),i.href="data:image/svg+xml;base64,"+u(s),o=document.createEvent("MouseEvents"),o.initMouseEvent("click",!0,!1,self,0,0,0,0,0,!1,!1,!1,!1,0,null),i.dispatchEvent(o)}function N(e,t,n){var r=function(e){return C(e,t,n)};return e.map(r)}function C(e,t,n){var r=Math.cos(-t)*(e.x-n.x)+Math.sin(-t)*(e.y-n.y)+n.x-e.x,i=-Math.sin(-t)*(e.x-n.x)+Math.cos(-t)*(e.y-n.y)+n.y-e.y;return{x:r,y:i}}function k(e){var t=e[1].x-e[0].x,n=e[1].y-e[0].y;return t==0&&n>=0?Math.PI/2:t==0&&n<0?3*Math.PI/2:t>=0&&n>=0?Math.atan(n/t):t>=0?Math.atan(n/t)+2*Math.PI:Math.atan(n/t)+Math.PI}function L(e){return e*180/Math.PI}function A(e,t,n){var r=Math.atan2(t.x-n.x,n.y-t.y),i=Math.atan2(t.x-n.x+e.x,n.y-t.y-e.y),s=i-r;return s}function O(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}function M(e,t){t.map(function(n,r){e[r]===undefined&&console.error("Argument is undefined: "+String(t[r]))})}function _(e,t){return e+"_"+t}function D(e){function n(e){var t=/(.*)_([a-z0-9]{1,2})$/,n=t.exec(e);return n===null?null:n.slice(1,3)}var t=n(e);return t===null&&(t=[e,null]),t}function P(e,t,n){if(typeof t=="string"){var r;if(t=="String")r=function(e){return typeof e=="string"};else if(t=="Float")r=function(e){return typeof e=="number"};else if(t=="Integer")r=function(e){return typeof e=="number"&&parseFloat(e,10)==parseInt(e,10)};else if(t=="Boolean")r=function(e){return typeof e=="boolean"};else if(t!="*")throw new Error("Bad spec string: "+t);if(!r(e))throw new Error("Bad type: "+String(e)+" should be "+t)}else if(t instanceof Array)e.forEach(function(e){P(e,t[0],n)});else{var i=Object.keys(t)[0];if(i=="*")for(var s in e){if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[i],n)}else for(var s in t){if(!(s in e))throw new Error("Missing key: %s"%s);if(e[s]===null&&n.indexOf(s)!=-1)continue;P(e[s],t[s],n)}}}function H(e){var t=e.reduce(function(e,t){return e+t}),n=t/e.length;return n}function B(e,t){e instanceof Array&&(e=e.node());while(e.parentNode!==null){e=e.parentNode;if(e.tagName===undefined)continue;if(e.tagName.toLowerCase()===t.toLowerCase())return!0}return!1}function j(e,t,n){t=t.replace(/^\/|\/$/g,"");var r=e.split(":"),i;if(["model","map"].indexOf(n)==-1)throw Error("Bad type: "+n);if(r.length!=(n=="model"?2:3))throw Error("Bad "+n+" name");n=="model"?i=["organisms",r[0],"models",r[1]+".json"].join("/"):i=["organisms",r[0],"models",r[1],"maps",r[2]+".json"].join("/");var s=[t,i].join("/");return s.replace(/^\/|\/$/g,"")}function F(e,t,n){t===undefined&&(t={});var r=e.location.search.substring(1),i=r.split("&");for(var s=0;s0?32:20};t.selectAll(".segment").datum(function(){return this.parentNode.__data__}).attr("d",function(e){if(e.from_node_id==null||e.to_node_id==null)return null;var t=r[e.from_node_id],n=r[e.to_node_id],i=e.b1,s=e.b2;if(t["node_type"]=="metabolite"&&i!==null){var o=a(e.reversibility,e.from_node_coefficient),u=i===null?n:i;t=g(o,t,u,"start")}if(n["node_type"]=="metabolite"){var o=a(e.reversibility,e.to_node_coefficient),u=s===null?t:s;n=g(o,u,n,"end")}var f="M"+t.x+","+t.y+" ";return i!==null&&s!==null&&(f+="C"+i.x+","+i.y+" "+s.x+","+s.y+" "),f+=n.x+","+n.y,f}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return t===null?o.color:n.reaction_color(t)}return null}).style("stroke-width",function(e){if(s&&u.indexOf("size")!==-1){var t=e.data;return t===null?o.size:n.reaction_size(t)}return null});var f=t.select(".arrowheads").selectAll(".arrowhead").data(function(t){var n=[],i=this.parentNode.parentNode.parentNode.__data__.reaction_id,s=this.parentNode.parentNode.__data__.segment_id,o=r[t.from_node_id],u=t.b1;if(o.node_type=="metabolite"&&(t.reversibility||t.from_node_coefficient>0)){var f=a(t.reversibility,t.from_node_coefficient),l=u===null?h:u,c=e.to_degrees(e.get_angle([o,l]))+90;o=g(f,o,l,"start"),n.push({data:t.data,x:o.x,y:o.y,rotation:c,show_arrowhead_flux:t.from_node_coefficient<0==t.reverse_flux||t.data==0})}var h=r[t.to_node_id],p=t.b2;if(h.node_type=="metabolite"&&(t.reversibility||t.to_node_coefficient>0)){var f=a(t.reversibility,t.to_node_coefficient),l=p===null?o:p,c=e.to_degrees(e.get_angle([h,l]))+90;h=g(f,l,h,"end"),n.push({data:t.data,x:h.x,y:h.y,rotation:c,show_arrowhead_flux:t.to_node_coefficient<0==t.reverse_flux||t.data==0})}return n});f.enter().append("path").classed("arrowhead",!0),f.attr("d",function(e){var t=20,r=13;if(s&&u.indexOf("size")!==-1){var i=e.data;t+=n.reaction_size(i)-n.reaction_size(0)}return"M"+[-t/2,0]+" L"+[0,r]+" L"+[t/2,0]+" Z"}).attr("transform",function(e){return"translate("+e.x+","+e.y+")rotate("+e.rotation+")"}).style("fill",function(e){if(s&&u.indexOf("color")!==-1){if(e.show_arrowhead_flux){var t=e.data;return n.reaction_color(t===null?0:t)}return"#FFFFFF"}return null}).style("stroke",function(e){if(s&&u.indexOf("color")!==-1){var t=e.data;return n.reaction_color(t===null?0:t)}return null}),f.exit().remove()}function c(t){e.check_undefined(arguments,["enter_selection"]);var n=t.append("g").attr("id",function(e){return e.bezier_id}).attr("class",function(e){return"bezier"});n.append("path").attr("class","connect-line"),n.append("circle").attr("class",function(e){return"bezier-circle "+e.bezier}).style("stroke-width",String(1)+"px").attr("r",String(7)+"px")}function h(t,r,i,s,o,u,a){e.check_undefined(arguments,["update_selection","show_beziers","drag_behavior","mouseover","mouseout","drawn_nodes","drawn_reactions"]);if(!r){t.attr("visibility","hidden");return}t.attr("visibility","visible"),t.select(".bezier-circle").call(n).call(i).on("mouseover",s).on("mouseout",o).attr("transform",function(e){return e.x==null||e.y==null?"":"translate("+e.x+","+e.y+")"}),t.select(".connect-line").attr("d",function(e){var t,n=a[e.reaction_id].segments[e.segment_id];return t=e.bezier=="b1"?u[n.from_node_id]:u[n.to_node_id],e.x==null||e.y==null||t.x==null||t.y==null?"":"M"+e.x+", "+e.y+" "+t.x+","+t.y})}function p(t,n,r){e.check_undefined(arguments,["enter_selection","drawn_nodes","drawn_reactions"]);var i=t.append("g").attr("class","node").attr("id",function(e){return"n"+e.node_id});i.append("circle").attr("class",function(e){var t="node-circle";return e.node_type!==null&&(t+=" "+e.node_type+"-circle"),t}),i.filter(function(e){return e.node_type=="metabolite"}).append("text").attr("class","node-label label")}function d(t,r,i,s,o,u,a,f,l){e.check_undefined(arguments,["update_selection","scale","has_metabolite_data","metabolite_data_styles","click_fn","mouseover_fn","mouseout_fn","drag_behavior","label_drag_behavior"]);var c=t.select(".node-circle").attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).attr("r",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("size")!==-1){var t=e.data;return r.metabolite_size(t===null?0:t)}return e.node_is_primary?15:10}return 5}).style("fill",function(e){if(e.node_type=="metabolite"){if(i&&s.indexOf("color")!==-1){var t=e.data;return r.metabolite_color(t===null?0:t)}return"rgb(224, 134, 91)"}return null}).call(n).call(f).on("click",o).on("mouseover",u).on("mouseout",a);t.select(".node-label").attr("transform",function(e){return"translate("+e.label_x+","+e.label_y+")"}).style("font-size",function(e){return String(20)+"px"}).text(function(e){var t=e.bigg_id;return i&&s.indexOf("text")!=-1&&(t+=" "+e.data_string),t}).call(n).call(l)}function v(t){e.check_undefined(arguments,["enter_selection"]),t.append("g").attr("id",function(e){return"l"+e.text_label_id}).attr("class","text-label").append("text").attr("class","label")}function m(t,r,i){e.check_undefined(arguments,["update_selection","label_click","label_drag_behavior"]),t.select(".label").text(function(e){return e.text}).attr("transform",function(e){return"translate("+e.x+","+e.y+")"}).on("click",r).call(n).call(i)}function g(t,n,r,i){e.check_undefined(arguments,["reaction_arrow_displacement","start","end","displace"]);var s=t,o=e.distance(n,r),u,a;return(!s||!o)&&console.error("Bad value"),i=="start"?(u=n.x+s*(r.x-n.x)/o,a=n.y+s*(r.y-n.y)/o):i=="end"?(u=r.x-s*(r.x-n.x)/o,a=r.y-s*(r.y-n.y)/o):console.error("bad displace value: "+i),{x:u,y:a}}return{create_reaction:s,update_reaction:o,create_bezier:c,update_bezier:h,create_node:p,update_node:d,create_text_label:v,update_text_label:m,create_membrane:r,update_membrane:i}}),n("build",["utils"],function(e){function t(t,r,i,o,u,a,f,c){c=Math.PI/180*c;var h=String(++a.reactions),p={x:u.x,y:u.y},d=300,v=[p,e.c_plus_c(p,{x:d,y:0})],m={x:(v[0].x+v[1].x)/2,y:(v[0].y+v[1].y)/2},g;Math.abs(c)e[1]?t:e},_=w.reduce(M,[0,0])[0],D=E.reduce(M,[0,0])[0];for(var N in b.metabolites){var C=b.metabolites[N];C.coefficient<0?(C.index==_&&(C.is_primary=!0),C.count=S+1):(C.index==D&&(C.is_primary=!0),C.count=x+1)}var P={},H=[{node_type:"anchor_reactants",dis:{x:y*(T?1:-1),y:0}},{node_type:"center",dis:{x:0,y:0}},{node_type:"anchor_products",dis:{x:y*(T?-1:1),y:0}}],B={};H.map(function(e){var t=String(++a.nodes),n=e.node_type=="center"?"midmarker":"multimarker";P[t]={node_type:n,x:m.x+e.dis.x,y:m.y+e.dis.y,connected_segments:[],name:null,bigg_id:null,label_x:null,label_y:null,node_is_primary:null},B[e.node_type]=t});var j=[[B.anchor_reactants,B.center],[B.anchor_products,B.center]];j.map(function(e){var t=e[0],n=e[1],r=String(++a.segments);b.segments[r]={b1:null,b2:null,from_node_id:t,to_node_id:n,from_node_coefficient:null,to_node_coefficient:null,reversibility:b.reversibility},P[t].connected_segments.push({segment_id:r,reaction_id:h}),P[n].connected_segments.push({segment_id:r,reaction_id:h})});var F=P;for(var N in b.metabolites){var C=b.metabolites[N],I,q;C.coefficient<0?(I=_,q=B.anchor_reactants):(I=D,q=B.anchor_products);var R=s(C,I,v,m,d,T);if(u.bigg_id==C.bigg_id){var U=String(++a.segments);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:o,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},u.connected_segments.push({segment_id:U,reaction_id:h}),F[q].connected_segments.push({segment_id:U,reaction_id:h})}else{var U=String(++a.segments),z=String(++a.nodes);b.segments[U]={b1:R.b1,b2:R.b2,from_node_id:q,to_node_id:z,from_node_coefficient:null,to_node_coefficient:C.coefficient,reversibility:b.reversibility},F[z]={connected_segments:[{segment_id:U,reaction_id:h}],x:R.circle.x,y:R.circle.y,node_is_primary:Boolean(C.is_primary),label_x:R.circle.x+g.x,label_y:R.circle.y+g.y,name:C.name,bigg_id:C.bigg_id,node_type:"metabolite"},F[q].connected_segments.push({segment_id:U,reaction_id:h})}}for(var t in b.metabolites)b.metabolites[t]={coefficient:b.metabolites[t].coefficient};var W={};W[h]=b;var X=l(W);return F[o]=u,n(F,W,X,c,p),{new_reactions:W,new_beziers:X,new_nodes:F}}function n(t,n,r,s,o){var a=function(t){return t===null?null:e.rotate_coords(t,s,o)},f=[],l=[];for(var c in t){var h=t[c],p=a({x:h.x,y:h.y}),d=i(h,n,p);h.connected_segments.map(function(t){var i=n[t.reaction_id];if(i===undefined)return;var s=t.segment_id,o=i.segments[s];if(o.to_node_id==c&&o.b2){var f=a(o.b2),l=u(s,"b2");o.b2=e.c_plus_c(o.b2,f),r[l].x=o.b2.x,r[l].y=o.b2.y}else if(o.from_node_id==c&&o.b1){var f=a(o.b1),l=u(s,"b1");o.b1=e.c_plus_c(o.b1,f),r[l].x=o.b1.x,r[l].y=o.b1.y}}),l=e.unique_concat([l,d.reaction_ids]),f.push(c)}return{node_ids:f,reaction_ids:l}}function r(t,n,r,s,o){var a=i(t,r,o);return t.connected_segments.map(function(t){var i=r[t.reaction_id];if(i===undefined)return;var f=t.segment_id,l=i.segments[f];[["b1","from_node_id"],["b2","to_node_id"]].forEach(function(t){var r=t[0],i=t[1];if(l[i]==n&&l[r]){l[r]=e.c_plus_c(l[r],o);var a=s[u(f,r)];a.x=l[r].x,a.y=l[r].y}}),a.reaction_ids.indexOf(t.reaction_id)<0&&a.reaction_ids.push(t.reaction_id)}),a}function i(e,t,n){e.x=e.x+n.x,e.y=e.y+n.y,e.label_x=e.label_x+n.x,e.label_y=e.label_y+n.y;var r=[];return e.connected_segments.map(function(i){var s=t[i.reaction_id];r.indexOf(i.reaction_id)<0&&(r.push(i.reaction_id),e.node_type=="midmarker"&&(s.label_x=s.label_x+n.x,s.label_y=s.label_y+n.y))}),{reaction_ids:r}}function s(t,n,r,i,s,o){var u=r[0],r=[e.c_minus_c(r[0],u),e.c_minus_c(r[1],u)],i=e.c_minus_c(i,u),a=80,f=.4,l=.25,c=a*.7,h=40,p=Math.min(2,t.count-1),d,v,m;t.is_primary?d=20:(d=10,t.index>n?v=t.index-1:v=t.index);var g=s-d,y=[{x:d,y:0},{x:g,y:0}],b,w,E,S;t.coefficient<0!=o&&t.is_primary?(b={x:y[0].x,y:y[0].y},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x,y:r[0].y}):t.coefficient<0!=o?(b={x:y[0].x+h,y:y[0].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[0].x*f,y:i.y*(1-f)+y[0].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[0].x+h,y:r[0].y+(a*v-a*(p-1)/2)}):t.coefficient>0!=o&&t.is_primary?(b={x:y[1].x,y:y[1].y},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x,y:r[1].y}):t.coefficient>0!=o&&(b={x:y[1].x-h,y:y[1].y+(c*v-c*(p-1)/2)},E={x:i.x*(1-f)+y[1].x*f,y:i.y*(1-f)+y[1].y*f},S={x:i.x*l+b.x*(1-l),y:i.y*l+b.y*(1-l)},w={x:r[1].x-h,y:r[1].y+(a*v-a*(p-1)/2)});var x={};return x.b1=e.c_plus_c(u,E),x.b2=e.c_plus_c(u,S),x.circle=e.c_plus_c(u,w),x}function o(e,t,n){var r=String(++e.text_labels),i={text:t,x:n.x,y:n.y};return{id:r,label:i}}function u(e,t){return e+"_"+t}function a(e){var t=[];for(var n in e){var r=e[n];for(var i in r.segments){var s=r.segments[i];["b1","b2"].forEach(function(e){var n=s[e];n!==null&&t.push(u(i,e))})}}return t}function f(e,t){var n={};for(var r in e){var i=e[r];["b1","b2"].forEach(function(e){var s=i[e];if(s!==null){var o=u(r,e);n[o]={bezier:e,x:s.x,y:s.y,reaction_id:t,segment_id:r}}})}return n}function l(t){var n={};for(var r in t){var i=t[r],s=f(i.segments,r);e.extend(n,s)}return n}return{new_reaction:t,rotate_nodes:n,move_node_and_dependents:r,new_text_label:o,bezier_id_for_segment_id:u,bezier_ids_for_reaction_ids:a,new_beziers_for_segments:f,new_beziers_for_reactions:l}}),n("Behavior",["utils","build"],function(e,t){function r(e,t){this.map=e,this.undo_stack=t,this.empty_behavior=function(){},this.rotation_mode_enabled=!1,this.rotation_drag=d3.behavior.drag(),this.selectable_click=null,this.text_label_click=null,this.selectable_drag=this.empty_behavior,this.node_mouseover=null,this.node_mouseout=null,this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null,this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior,this.turn_everything_on()}function i(){this.toggle_selectable_click(!0),this.toggle_selectable_drag(!0),this.toggle_label_drag(!0)}function s(){this.toggle_selectable_click(!1),this.toggle_selectable_drag(!1),this.toggle_label_drag(!1)}function o(n){function g(){var e=this.map.sel.selectAll("#rotation-center").data([0]),t=e.enter().append("g").attr("id","rotation-center");t.append("path").attr("d","M-22 0 L22 0").attr("class","rotation-center-line"),t.append("path").attr("d","M0 -22 L0 22").attr("class","rotation-center-line"),e.attr("transform","translate("+this.center.x+","+this.center.y+")").attr("visibility","visible"),e.call(d3.behavior.drag().on("drag",function(e){var t=d3.transform(e.attr("transform")),n=[d3.event.dx+t.translate[0],d3.event.dy+t.translate[1]];e.attr("transform","translate("+n+")"),this.center={x:n[0],y:n[1]}}.bind(this,e))),e.on("mouseover",function(){var e=parseFloat(this.selectAll("path").style("stroke-width"));this.selectAll("path").style("stroke-width",e*2+"px")}.bind(e)),e.on("mouseout",function(){this.selectAll("path").style("stroke-width",null)}.bind(e))}function y(e){this.map.sel.select("#rotation-center").attr("visibility","hidden")}function b(t){var n=[],r=[];for(var i in t){var s=t[i];s.x!==undefined&&n.push(s.x),s.y!==undefined&&r.push(s.y)}return{x:e.mean(n),y:e.mean(r)}}n===undefined?this.rotation_mode_enabled=!this.rotation_mode_enabled:this.rotation_mode_enabled=n;var r=this.map.sel.selectAll(".node-circle"),i=this.map.sel.selectAll("#canvas");if(this.rotation_mode_enabled){this.map.callback_manager.run("start_rotation");var s=this.map.get_selected_nodes();if(Object.keys(s).length==0){console.warn("No selected nodes");return}this.center=b(s),g.call(this);var o=this.map,u=Object.keys(s),a=this.map.reactions,f=this.map.nodes,l=this.map.beziers,c=function(e){d3.event.sourceEvent.stopPropagation()},h=function(e,n,r,i){var u=t.rotate_nodes(s,a,l,n,i);o.draw_these_nodes(u.node_ids),o.draw_these_reactions(u.reaction_ids)},p=function(e){},d=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,-n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},v=function(e,n,r){var i={};u.forEach(function(e){i[e]=f[e]});var s=t.rotate_nodes(i,a,l,n,r);o.draw_these_nodes(s.node_ids),o.draw_these_reactions(s.reaction_ids)},m=function(){return this.center}.bind(this);this.rotation_drag=this._get_generic_angular_drag(c,h,p,d,v,m,this.map.sel),i.call(this.rotation_drag)}else y.call(this),r.on("mousedown.center",null),i.on("mousedown.center",null),i.on("mousedown.drag",null),i.on("touchstart.drag",null),this.rotation_drag=null}function u(e){e===undefined&&(e=this.selectable_click==null);if(e){var t=this.map;this.selectable_click=function(e){if(d3.event.defaultPrevented)return;t.select_selectable(this,e),d3.event.stopPropagation()},this.node_mouseover=function(e){d3.select(this).style("stroke-width",null);var t=parseFloat(d3.select(this).style("stroke-width"));d3.select(this).style("stroke-width",t*2+"px")},this.node_mouseout=function(e){d3.select(this).style("stroke-width",null)}}else this.selectable_click=null,this.node_mouseover=null,this.node_mouseout=null,this.map.sel.select("#nodes").selectAll(".node-circle").style("stroke-width",null)}function a(e){e===undefined&&(e=this.text_edit_click==null);if(e){var t=this.map,n=this.selection;this.text_label_click=function(){if(d3.event.defaultPrevented)return;var e=d3.transform(d3.select(this).attr("transform")).translate,n={x:e[0],y:e[1]};t.callback_manager.run("edit_text_label",d3.select(this),n),d3.event.stopPropagation()},this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!0),this.map.sel.on("click.new_text_label",function(e){var t={x:d3.mouse(e)[0],y:d3.mouse(e)[1]};this.map.callback_manager.run("new_text_label",t)}.bind(this,this.map.sel.node()))}else this.text_label_click=this.selectable_click,this.map.sel.select("#text-labels").selectAll(".label").classed("edit-text-cursor",!1),this.map.sel.on("click.new_text_label",null)}function f(e){e===undefined&&(e=this.selectable_drag===this.empty_behavior),e?(this.selectable_drag=this._get_selectable_drag(this.map,this.undo_stack),this.bezier_drag=this._get_bezier_drag(this.map,this.undo_stack)):(this.selectable_drag=this.empty_behavior,this.bezier_drag=this.empty_behavior)}function l(e){e===undefined&&(e=this.label_drag===this.empty_behavior),e?(this.reaction_label_drag=this._get_reaction_label_drag(this.map),this.node_label_drag=this._get_node_label_drag(this.map)):(this.reaction_label_drag=this.empty_behavior,this.node_label_drag=this.empty_behavior)}function c(e){e===undefined&&(e=this.bezier_drag===this.empty_behavior),e?(this.bezier_drag=this._get_bezier_drag(this.map),this.bezier_mouseover=function(e){d3.select(this).style("stroke-width",String(3)+"px")},this.bezier_mouseout=function(e){d3.select(this).style("stroke-width",String(1)+"px")}):(this.bezier_drag=this.empty_behavior,this.bezier_mouseover=null,this.bezier_mouseout=null)}function h(n,r){function c(t,r){var i=n.nodes[r],s=n.nodes[t],o=[];return i.connected_segments.forEach(function(i){var u=n.reactions[i.reaction_id].segments[i.segment_id];if(u.from_node_id==r)u.from_node_id=t;else{if(u.to_node_id!=r)return console.error("Segment does not connect to dragged node");u.to_node_id=t}return s.connected_segments.push(i),o.push(e.clone(i)),null}),n.delete_node_data([r]),n.sel.selectAll(".node-to-combine").classed("node-to-combine",!1),n.draw_everything(),o}var i=d3.behavior.drag(),s=null,o=null,u=null,a=null,f=null,l=function(e,t){var r=n.text_labels[e];r.x=r.x+t.x,r.y=r.y+t.y};return i.on("dragstart",function(){d3.event.sourceEvent.stopPropagation(),o={x:0,y:0};if(d3.select(this).attr("class").indexOf("label")==-1){var e=this.parentNode.__data__,t=e.bigg_id,r=this.parentNode;s=window.setTimeout(function(){r.parentNode.insertBefore(r,r.parentNode.firstChild)},200),n.sel.selectAll(".metabolite-circle").on("mouseover.combine",function(n){n.bigg_id==t&&n.node_id!=e.node_id&&d3.select(this).style("stroke-width",String(12)+"px").classed("node-to-combine",!0)}).on("mouseout.combine",function(e){e.bigg_id==t&&n.sel.selectAll(".node-to-combine").style("stroke-width",String(2)+"px").classed("node-to-combine",!1)})}}),i.on("drag",function(){var r={};d3.select(this).attr("class").indexOf("label")==-1?(r.type="node",r.id=this.parentNode.__data__.node_id):(r.type="label",r.id=this.__data__.text_label_id);var i=n.get_selected_node_ids(),s=n.get_selected_text_label_ids();u=[],f=[],r["type"]=="node"&&i.indexOf(r["id"])==-1?u.push(r.id):r["type"]=="label"&&s.indexOf(r["id"])==-1?f.push(r.id):(u=i,f=s),a=[];var c={x:d3.event.dx,y:d3.event.dy};o=e.c_plus_c(o,c),u.forEach(function(r){var i=n.nodes[r],s=t.move_node_and_dependents(i,r,n.reactions,n.beziers,c);a=e.unique_concat([a,s.reaction_ids])}),f.forEach(function(e){l(e,c)}),n.draw_these_nodes(u),n.draw_these_reactions(a),n.draw_these_text_labels(f)}),i.on("dragend",function(){if(u===null){o=null,u=null,f=null,a=null,s=null;return}var i=[];n.sel.selectAll(".node-to-combine").each(function(e){i.push(e.node_id)});if(i.length==1){var h=i[0],p=this.parentNode.__data__.node_id,d=e.clone(n.nodes[p]),v=c(h,p);r.push(function(){n.nodes[p]=d;var e=n.nodes[h],t=[];v.forEach(function(r){var i=n.reactions[r.reaction_id].segments[r.segment_id];i.from_node_id==h?i.from_node_id=p:i.to_node_id==h?i.to_node_id=p:console.error("Segment does not connect to fixed node"),e.connected_segments=e.connected_segments.filter(function(e){return e.reaction_id!=r.reaction_id||e.segment_id!=r.segment_id}),t.indexOf(r.reaction_id)==-1&&t.push(r.reaction_id)}),n.draw_these_nodes([p]),n.draw_these_reactions(t)},function(){c(h,p)})}else{var m=e.clone(o),g=e.clone(u),y=e.clone(f),b=e.clone(a);r.push(function(){g.forEach(function(r){var i=n.nodes[r];t.move_node_and_dependents(i,r,n.reactions,n.beziers,e.c_times_scalar(m,-1))}),y.forEach(function(t){l(t,e.c_times_scalar(m,-1))}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)},function(){g.forEach(function(e){var r=n.nodes[e];t.move_node_and_dependents(r,e,n.reactions,n.beziers,m)}),y.forEach(function(e){l(e,m)}),n.draw_these_nodes(g),n.draw_these_reactions(b),n.draw_these_text_labels(y)})}n.sel.selectAll(".metabolite-circle").on("mouseover.combine",null).on("mouseout.combine",null),window.clearTimeout(s),o=null,u=null,f=null,a=null,s=null}),i}function p(t){var n=function(n,r,i,s,o){var u=t.reactions[n].segments[r];u[i]=e.c_plus_c(u[i],o),t.beziers[s].x=u[i].x,t.beziers[s].y=u[i].y},r=function(e){e.dragging=!0},i=function(e,r,i){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])},s=function(e){e.dragging=!1},o=function(r,i){n(r.reaction_id,r.segment_id,r.bezier,r.bezier_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id],!1),t.draw_these_beziers([r.bezier_id])},u=function(e,r){n(e.reaction_id,e.segment_id,e.bezier,e.bezier_id,r),t.draw_these_reactions([e.reaction_id],!1),t.draw_these_beziers([e.bezier_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function d(t){var n=function(e,n){var r=t.reactions[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])},s=function(e){},o=function(r,i){n(r.reaction_id,e.c_times_scalar(i,-1)),t.draw_these_reactions([r.reaction_id])},u=function(e,r){n(e.reaction_id,r),t.draw_these_reactions([e.reaction_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function v(t){var n=function(e,n){var r=t.nodes[e];r.label_x=r.label_x+n.x,r.label_y=r.label_y+n.y},r=function(e){},i=function(e,r,i){n(e.node_id,r),t.draw_these_nodes([e.node_id])},s=function(e){},o=function(r,i){n(r.node_id,e.c_times_scalar(i,-1)),t.draw_these_nodes([r.node_id])},u=function(e,r){n(e.node_id,r),t.draw_these_nodes([e.node_id])};return this._get_generic_drag(r,i,s,o,u,this.map.sel)}function m(t,n,r,i,s,o){var u=d3.behavior.drag(),a,f=this.undo_stack,l=o.node();return u.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),a={x:0,y:0},t(e)}),u.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};a=e.c_plus_c(a,r),n(t,r,a,i)}),u.on("dragend",function(t){var n=e.clone(t),o=e.clone(a),u={x:d3.mouse(l)[0],y:d3.mouse(l)[1]};f.push(function(){i(n,o,u)},function(){s(n,o,u)}),r(t)}),u}function g(t,n,r,i,s,o,u){var a=d3.behavior.drag(),f,l=this.undo_stack,c=u.node();return a.on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),f=0,t(e)}),a.on("drag",function(t){var r={x:d3.event.dx,y:d3.event.dy},i={x:d3.mouse(c)[0],y:d3.mouse(c)[1]},s=o(),u=e.angle_for_event(r,i,s);f+=u,n(t,u,f,s)}),a.on("dragend",function(t){var n=e.clone(t),u=f,a=e.clone(o());l.push(function(){i(n,u,a)},function(){s(n,u,a)}),r(t)}),a}var n=e.make_class();return n.prototype={init:r,toggle_rotation_mode:o,turn_everything_on:i,turn_everything_off:s,toggle_selectable_click:u,toggle_text_label_edit:a,toggle_selectable_drag:f,toggle_label_drag:l,toggle_bezier_drag:c,_get_selectable_drag:h,_get_bezier_drag:p,_get_reaction_label_drag:d,_get_node_label_drag:v,_get_generic_drag:m,_get_generic_angular_drag:g},n}),n("Scale",["utils"],function(e){function n(){this.x=d3.scale.linear(),this.y=d3.scale.linear(),this.x_size=d3.scale.linear(),this.y_size=d3.scale.linear(),this.size=d3.scale.linear(),this.reaction_color=d3.scale.linear().clamp(!0),this.reaction_size=d3.scale.linear().clamp(!0),this.metabolite_color=d3.scale.linear().clamp(!0),this.metabolite_size=d3.scale.linear().clamp(!0),this.scale_path=function(e){var t=this.x,n=this.y,r=d3.format(".2f"),e=e.replace(/(M|L)([0-9-.]+),?\s*([0-9-.]+)/g,function(e,i,s,o){return i+[r(t(parseFloat(s))),r(n(parseFloat(o)))].join(", ")}),i=/C([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)\s*([0-9-.]+),?\s*([0-9-.]+)/g;return e=e.replace(i,function(e,i,s,o,u,a,f){return"C"+r(t(parseFloat(i)))+","+r(n(parseFloat(s)))+" "+r(t(parseFloat(o)))+","+r(n(parseFloat(u)))+" "+[r(t(parseFloat(a)))+","+r(n(parseFloat(f)))]}),e}.bind(this),this.scale_decimals=function(e,t,n){var r=d3.format("."+String(n)+"f");return e=e.replace(/([0-9.]+)/g,function(e,n){return r(t(parseFloat(n)))}),e}}function r(e){e.domain_stream.reaction.onValue(function(e){this.reaction_color.domain(e),this.reaction_size.domain(e)}.bind(this)),e.domain_stream.metabolite.onValue(function(e){this.metabolite_color.domain(e),this.metabolite_size.domain(e)}.bind(this)),e.range_stream.reaction.color.onValue(function(e){this.reaction_color.range(e)}.bind(this)),e.range_stream.reaction.size.onValue(function(e){this.reaction_size.range(e)}.bind(this)),e.range_stream.metabolite.color.onValue(function(e){this.metabolite_color.range(e)}.bind(this)),e.range_stream.metabolite.size.onValue(function(e){this.metabolite_size.range(e)}.bind(this))}var t=e.make_class();return t.prototype={init:n,connect_to_settings:r},t}),n("UndoStack",["utils"],function(e){function n(){var e=40;this.stack=Array(e),this.current=-1,this.oldest=-1,this.newest=-1,this.end_of_stack=!0,this.top_of_stack=!0}function r(e,t){this.current=o(this.current,this.stack.length),this.end_of_stack?this.oldest=this.current:this.oldest==this.current&&(this.oldest=o(this.oldest,this.stack.length)),this.stack[this.current]={undo:e,redo:t},this.newest=this.current,this.top_of_stack=!0,this.end_of_stack=!1}function i(){if(this.end_of_stack)return console.warn("End of stack.");this.stack[this.current].undo(),this.current==this.oldest?this.end_of_stack=!0:this.current=u(this.current,this.stack.length),this.top_of_stack=!1}function s(){if(this.top_of_stack)return console.warn("Top of stack.");this.end_of_stack||(this.current=o(this.current,this.stack.length)),this.stack[this.current].redo(),this.current==this.newest&&(this.top_of_stack=!0),this.end_of_stack=!1}function o(e,t){return e+1>t-1?0:e+1}function u(e,t){return e-1<0?t-1:e-1}var t=e.make_class();return t.prototype={init:n,push:r,undo:i,redo:s},t}),n("CallbackManager",["utils"],function(e){function n(){}function r(e,t){return this.callbacks===undefined&&(this.callbacks={}),this.callbacks[e]===undefined&&(this.callbacks[e]=[]),this.callbacks[e].push(t),this}function i(e){return(this.callbacks===undefined||Object.keys(this.callbacks).length==0)&&console.warn("No callbacks to remove"),delete this.callbacks[e],this}function s(e){if(this.callbacks===undefined)return this;var t=Array.prototype.slice.call(arguments,1);for(var n in this.callbacks){var r=n.split(".")[0];r==e&&this.callbacks[n].forEach(function(e){e.apply(null,t)})}return this}var t=e.make_class();return t.prototype={init:n,set:r,remove:i,run:s},t}),n("KeyManager",["utils"],function(e){function n(e){e.command=!1,e.control=!1,e.option=!1,e.shift=!1}function r(e,t,r){e===undefined?this.assigned_keys={}:this.assigned_keys=e,t===undefined?this.input_list=[]:this.input_list=t,r===undefined&&(r=!0),this.ctrl_equals_cmd=r,this.held_keys={},n(this.held_keys),this.enabled=!0,this.update()}function i(){function o(e,t,n,r){for(var i in e)e[i]==n&&(t[i]=r)}function u(t,n,r,i){if(t.key!=n)return!1;var s=e.clone(t.modifiers);s===undefined&&(s={control:!1,command:!1,option:!1,shift:!1});for(var o in r){if(i&&s.control&&(o=="command"||o=="command_right"||o=="control")&&(r.command||r.command_right||r.control))continue;s[o]===undefined&&(s[o]=!1);if(s[o]!=r[o])return!1}return!0}var t=this.held_keys,r=this.assigned_keys,i=this,s={command:91,command_right:93,control:17,option:18,shift:16};d3.select(window).on("keydown.key_manager",null),d3.select(window).on("keyup.key_manager",null);if(!this.enabled)return;d3.select(window).on("keydown.key_manager",function(e,i){var a=d3.event.keyCode,f=!0,l=!1;i.forEach(function(e){e.is_visible()&&(l=!0)}),o(s,t,a,!0);for(var c in r){var h=r[c];if(u(h,a,t,e)){f=!1;if(!h.ignore_with_input||!l)h.fn?h.fn.call(h.target):console.warn("No function for key"),d3.event.preventDefault()}}for(var p in s)s[p]==a&&(f=!1);f&&n(t)}.bind(null,this.ctrl_equals_cmd,this.input_list)).on("keyup.key_manager",function(){o(s,t,d3.event.keyCode,!1)})}function s(e){e===undefined&&(e=!this.enabled),this.enabled=e,this.update()}function o(e){this.add_key_listener(e,13)}function u(e){this.add_key_listener(e,27)}function a(e,t){var n=d3.select(window);return n.on("keydown."+t,function(){d3.event.keyCode==t&&e()}),{clear:function(){n.on("keydown."+t,null)}}}var t=e.make_class();return t.reset_held_keys=n,t.prototype={init:r,update:i,toggle:s,add_escape_listener:u,add_enter_listener:o,add_key_listener:a},t}),n("Canvas",["utils","CallbackManager"],function(e,t){function r(e,n){this.selection=e,this.x=n.x,this.y=n.y,this.width=n.width,this.height=n.height,this.resize_enabled=!0,this.callback_manager=new t,this.setup()}function i(e){e===undefined&&(e=!this.resize_enabled),e?this.selection.selectAll(".drag-rect").style("pointer-events","auto"):this.selection.selectAll(".drag-rect").style("pointer-events","none")}function s(){function v(){d3.event.sourceEvent.stopPropagation()}function m(e,t,n){var r=d3.transform(n),i=r.translate;return e!==null&&(i[0]=e),t!==null&&(i[1]=t),"translate("+i+")"}function g(t){var i=t.x;t.x=Math.min(t.x+e.width-n/2,d3.event.x),e.x=t.x,e.width=e.width+(i-t.x),c.attr("transform",function(e){return m(e.x-n/2,null,c.attr("transform"))}),s.attr("transform",function(e){return m(e.x,null,s.attr("transform"))}).attr("width",e.width*r),o.attr("transform",function(e){return m(e.x,null,o.attr("transform"))}).attr("width",e.width),p.attr("transform",function(e){return m(e.x+n/2,null,p.attr("transform"))}).attr("width",e.width-n),d.attr("transform",function(e){return m(e.x+n/2,null,d.attr("transform"))}).attr("width",e.width-n),e.callback_manager.run("resize")}function y(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.x+n/2,t.x+e.width+d3.event.dx);e.width=i-t.x,h.attr("transform",function(e){return m(i-n/2,null,h.attr("transform"))}),s.attr("width",e.width*r),o.attr("width",e.width),p.attr("width",e.width-n),d.attr("width",e.width-n),e.callback_manager.run("resize")}function b(t){d3.event.sourceEvent.stopPropagation();var i=t.y;t.y=Math.min(t.y+e.height-n/2,d3.event.y),e.y=t.y,e.height=e.height+(i-t.y),p.attr("transform",function(e){return m(null,e.y-n/2,p.attr("transform"))}),s.attr("transform",function(e){return m(null,e.y,s.attr("transform"))}).attr("width",e.height*r),o.attr("transform",function(e){return m(null,e.y,o.attr("transform"))}).attr("height",e.height),c.attr("transform",function(e){return m(null,e.y+n/2,c.attr("transform"))}).attr("height",e.height-n),h.attr("transform",function(e){return m(null,e.y+n/2,h.attr("transform"))}).attr("height",e.height-n),e.callback_manager.run("resize")}function w(t){d3.event.sourceEvent.stopPropagation();var i=Math.max(t.y+n/2,t.y+e.height+d3.event.dy);e.height=i-t.y,d.attr("transform",function(e){return m(null,i-n/2,d.attr("transform"))}),s.attr("height",e.height*r),o.attr("height",e.height),c.attr("height",e.height-n),h.attr("height",e.height-n),e.callback_manager.run("resize")}var e=this,t={x:this.width,y:this.height},n=20,r=10,i=this.selection.append("g").classed("canvas-group",!0).data([{x:this.x,y:this.y}]),s=i.append("rect").attr("id","mouse-node").attr("width",this.width*r).attr("height",this.height*r).attr("transform","translate("+[e.x-this.width*r/2,e.y-this.height*r/2]+")").attr("pointer-events","all");this.mouse_node=s;var o=i.append("rect").attr("id","canvas").attr("width",this.width).attr("height",this.height).attr("transform","translate("+[e.x,e.y]+")"),u=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",y),a=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",g),f=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",b),l=d3.behavior.drag().origin(Object).on("dragstart",v).on("drag",w),c=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x-n/2,e.y+n/2]+")"}).attr("height",this.height-n).attr("id","dragleft").attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(a),h=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+e.width-n/2,t.y+n/2]+")"}).attr("id","dragright").attr("height",this.height-n).attr("width",n).attr("cursor","ew-resize").classed("resize-rect",!0).call(u),p=i.append("rect").classed("drag-rect",!0).attr("transform",function(e){return"translate("+[e.x+n/2,e.y-n/2]+")"}).attr("height",n).attr("id","dragtop").attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(f),d=i.append("rect").classed("drag-rect",!0).attr("transform",function(t){return"translate("+[t.x+n/2,t.y+e.height-n/2]+")"}).attr("id","dragbottom").attr("height",n).attr("width",this.width-n).attr("cursor","ns-resize").classed("resize-rect",!0).call(l)}function o(){return{x:this.x,y:this.y,width:this.width,height:this.height}}var n=e.make_class();return n.prototype={init:r,toggle_resize:i,setup:s,size_and_location:o},n}),n("SearchIndex",["utils"],function(e){function n(){this.index={}}function r(e,t,n,r){if(!n&&e in this.index)throw new Error("id is already in the index");if(!(!r||"name"in t&&"data"in t))throw new Error("malformed record");this.index[e]=t}function i(e){return e in this.index?(delete this.index[e],!0):!1}function s(e){var t=RegExp(e,"i"),n=[];for(var r in this.index){var i=this.index[r];t.exec(i.name)&&n.push(i.data)}return n}var t=e.make_class();return t.prototype={init:n,insert:r,remove:i,find:s},t}),function(){var e,t,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K,Q,G,Y,Z,et,tt,nt,rt,it,st,ot,ut,at,ft,lt,ct,ht=[].slice,pt={}.hasOwnProperty,dt=function(e,t){function r(){this.constructor=e}for(var n in t)pt.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},vt=function(e,t){return function(){return e.apply(t,arguments)}};e={toString:function(){return"Bacon"}},e.version="0.7.12",e.fromBinder=function(t,n){return n==null&&(n=lt.id),new c(_(e,"fromBinder",t,n),function(r){var i;return i=t(function(){var t,s,o,u,a,f;t=1<=arguments.length?ht.call(arguments,0):[],u=n.apply(null,t),I(u)&<.last(u)instanceof l||(u=[u]),o=e.more;for(a=0,f=u.length;a"],e.more=[""],e.later=function(t,n){return at(e,"later",t,n,e.sequentially(t,[n]))},e.sequentially=function(t,n){var r;return r=0,at(e,"sequentially",t,n,e.fromPoll(t,function(){var e;return e=n[r++],r0?o({error:t,retriesDone:i-s}):e.once(new e.Error(t))}))},P=0,l=function(){function e(){this.id=++P}return e.prototype.isEvent=function(){return!0},e.prototype.isEnd=function(){return!1},e.prototype.isInitial=function(){return!1},e.prototype.isNext=function(){return!1},e.prototype.isError=function(){return!1},e.prototype.hasValue=function(){return!1},e.prototype.filter=function(){return!0},e.prototype.inspect=function(){return this.toString()},e.prototype.log=function(){return this.toString()},e}(),p=function(e){function t(e){t.__super__.constructor.call(this),R(e)?this.value=lt.cached(e):this.value=lt.always(e)}return dt(t,e),t.prototype.isNext=function(){return!0},t.prototype.hasValue=function(){return!0},t.prototype.fmap=function(e){var t;return t=this.value,this.apply(function(){return e(t())})},t.prototype.apply=function(e){return new t(e)},t.prototype.filter=function(e){return e(this.value())},t.prototype.toString=function(){return lt.toString(this.value())},t.prototype.log=function(){return this.value()},t}(l),h=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isInitial=function(){return!0},t.prototype.isNext=function(){return!1},t.prototype.apply=function(e){return new t(e)},t.prototype.toNext=function(){return new p(this.value)},t}(p),a=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return dt(t,e),t.prototype.isEnd=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return""},t}(l),f=function(e){function t(e){this.error=e}return dt(t,e),t.prototype.isError=function(){return!0},t.prototype.fmap=function(){return this},t.prototype.apply=function(){return this},t.prototype.toString=function(){return" "+lt.toString(this.error)},t}(l),j=0,v=function(){function t(e){this.flatMapError=vt(this.flatMapError,this),this.id=++j,at(e,this)}return t.prototype.onValue=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.hasValue())return e(t.value())})},t.prototype.onValues=function(e){return this.onValue(function(t){return e.apply(null,t)})},t.prototype.onError=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isError())return e(t.error)})},t.prototype.onEnd=function(){var e;return e=V(arguments),this.subscribe(function(t){if(t.isEnd())return e()})},t.prototype.errors=function(){return at(this,"errors",this.filter(function(){return!1}))},t.prototype.filter=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"filter",t,this.withHandler(function(n){return n.filter(t)?this.push(n):e.more}))})},t.prototype.takeWhile=function(){var t,n;return n=arguments[0],t=2<=arguments.length?ht.call(arguments,1):[],M(this,n,t,function(t){return at(this,"takeWhile",t,this.withHandler(function(n){return n.filter(t)?this.push(n):(this.push(D()),e.noMore)}))})},t.prototype.endOnError=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t==null&&(t=!0),M(this,t,e,function(e){return at(this,"endOnError",this.withHandler(function(t){return t.isError()&&e(t.error)?(this.push(t),this.push(D())):this.push(t)}))})},t.prototype.take=function(t){return t<=0?e.never():at(this,"take",t,this.withHandler(function(n){return n.hasValue()?(t--,t>0?this.push(n):(t===0&&this.push(n),this.push(D()),e.noMore)):this.push(n)}))},t.prototype.map=function(){var e,t;return t=arguments[0],e=2<=arguments.length?ht.call(arguments,1):[],t instanceof m?t.sampledBy(this,B):M(this,t,e,function(e){return at(this,"map",e,this.withHandler(function(t){return this.push(t.fmap(e))}))})},t.prototype.mapError=function(){var e;return e=V(arguments),at(this,"mapError",e,this.withHandler(function(t){return t.isError()?this.push(Q(e(t.error))):this.push(t)}))},t.prototype.mapEnd=function(){var t;return t=V(arguments),at(this,"mapEnd",t,this.withHandler(function(n){return n.isEnd()?(this.push(Q(t(n))),this.push(D()),e.noMore):this.push(n)}))},t.prototype.doAction=function(){var e;return e=V(arguments),at(this,"doAction",e,this.withHandler(function(t){return t.hasValue()&&e(t.value()),this.push(t)}))},t.prototype.skip=function(t){return at(this,"skip",t,this.withHandler(function(n){return n.hasValue()?t>0?(t--,e.more):this.push(n):this.push(n)}))},t.prototype.skipDuplicates=function(e){return e==null&&(e=function(e,t){return e===t}),at(this,"skipDuplicates",this.withStateMachine(d,function(t,n){return n.hasValue()?n.isInitial()||t===d||!e(t.get(),n.value())?[new y(n.value()),[n]]:[t,[]]:[t,[n]]}))},t.prototype.skipErrors=function(){return at(this,"skipErrors",this.withHandler(function(t){return t.isError()?e.more:this.push(t)}))},t.prototype.withStateMachine=function(t,n){var r;return r=t,at(this,"withStateMachine",t,n,this.withHandler(function(t){var i,s,o,u,a,f,l;i=n(r,t),s=i[0],u=i[1],r=s,a=e.more;for(f=0,l=u.length;f=t}))},t.prototype.combine=function(t,n){var r;return r=nt(n),at(this,"combine",t,n,e.combineAsArray(this,t).map(function(e){return r(e[0],e[1])}))},t.prototype.decode=function(t){return at(this,"decode",t,this.combine(e.combineTemplate(t),function(e,t){return t[e]}))},t.prototype.awaiting=function(t){return at(this,"awaiting",t,e.groupSimultaneous(this,t).map(function(e){var t,n;return t=e[0],n=e[1],n.length===0}).toProperty(!1).skipDuplicates())},t.prototype.name=function(e){return this.toString=function(){return e},this},t.prototype.withDescription=function(){return _.apply(null,arguments).apply(this)},t}(),v.prototype.reduce=v.prototype.fold,v.prototype.assign=v.prototype.onValue,H=function(t,n,r){return new c(_(t,"flatMap"+(r?"First":""),n),function(s){var o,u;return u=new i,o=function(e){e();if(u.empty())return s(D())},u.add(function(i,a){return t.subscribeInternal(function(t){var i;return t.isEnd()?o(a):t.isError()?s(t):r&&u.count()>1?e.more:u.unsubscribed?e.noMore:(i=J(n(t.value())),u.add(function(t,n){return i.subscribeInternal(function(r){var i;return r.isEnd()?(o(n),e.noMore):(r instanceof h&&(r=r.toNext()),i=s(r),i===e.noMore&&t(),i)})}))})}),u.unsubscribe})},c=function(t){function n(e,t){var r;R(e)&&(t=e,e=[]),n.__super__.constructor.call(this,e),N(t),r=new u(t),this.subscribeInternal=r.subscribe,this.subscribe=w.wrappedSubscribe(this),this.hasSubscribers=r.hasSubscribers,et(this)}return dt(n,t),n.prototype.delay=function(t){return at(this,"delay",t,this.flatMap(function(n){return e.later(t,n)}))},n.prototype.debounce=function(t){return at(this,"debounce",t,this.flatMapLatest(function(n){return e.later(t,n)}))},n.prototype.debounceImmediate=function(t){return at(this,"debounceImmediate",t,this.flatMapFirst(function(n){return e.once(n).concat(e.later(t).filter(!1))}))},n.prototype.throttle=function(e){return at(this,"throttle",e,this.bufferWithTime(e).map(function(e){return e[e.length-1]}))},n.prototype.bufferWithTime=function(e){return at(this,"bufferWithTime",e,this.bufferWithTimeOrCount(e,Number.MAX_VALUE))},n.prototype.bufferWithCount=function(e){return at(this,"bufferWithCount",e,this.bufferWithTimeOrCount(void 0,e))},n.prototype.bufferWithTimeOrCount=function(e,t){var n;return n=function(n){if(n.values.length===t)return n.flush();if(e!==void 0)return n.schedule()},at(this,"bufferWithTimeOrCount",e,t,this.buffer(e,n,n))},n.prototype.buffer=function(t,n,r){var i,s,o;return n==null&&(n=function(){}),r==null&&(r=function(){}),i={scheduled:!1,end:null,values:[],flush:function(){var t;this.scheduled=!1;if(this.values.length>0){t=this.push(Q(this.values)),this.values=[];if(this.end!=null)return this.push(this.end);if(t!==e.noMore)return r(this)}else if(this.end!=null)return this.push(this.end)},schedule:function(){if(!this.scheduled)return this.scheduled=!0,t(function(e){return function(){return e.flush()}}(this))}},o=e.more,R(t)||(s=t,t=function(t){return e.scheduler.setTimeout(t,s)}),at(this,"buffer",this.withHandler(function(e){return i.push=this.push,e.isError()?o=this.push(e):e.isEnd()?(i.end=e,i.scheduled||i.flush()):(i.values.push(e.value()),n(i)),o}))},n.prototype.merge=function(t){var n;return T(t),n=this,at(n,"merge",t,e.mergeAll(this,t))},n.prototype.toProperty=function(e){return arguments.length===0&&(e=d),at(this,"toProperty",e,this.scan(e,z,!0))},n.prototype.toEventStream=function(){return this},n.prototype.sampledBy=function(e,t){return at(this,"sampledBy",e,t,this.toProperty().sampledBy(e,t))},n.prototype.concat=function(e){var t;return t=this,new n(_(t,"concat",e),function(n){var r,i;return i=G,r=t.subscribeInternal(function(t){return t.isEnd()?i=e.subscribeInternal(n):n(t)}),function(){return r(),i()}})},n.prototype.takeUntil=function(t){var n;return n={},at(this,"takeUntil",t,e.groupSimultaneous(this.mapEnd(n),t.skipErrors()).withHandler(function(r){var i,s,o,u,a,f;if(!r.hasValue())return this.push(r);f=r.value(),i=f[0],t=f[1];if(t.length)return this.push(D());s=e.more;for(u=0,a=i.length;u0},s=null,c=G,f=function(e){return l=lt.without(e,l)},h=null,r=function(){var e,t,n,r,i;if(h!=null){t=h,h=null,i=[];for(n=0,r=t.length;n=e},t.prototype.hasAtLeast=function(e){return this.queue.length>=e},t.prototype.flatten=!1,t}(b),t=function(e){function t(e){this.obs=e,t.__super__.constructor.call(this,this.obs,!0,this.obs.subscribeInternal)}return dt(t,e),t.prototype.consume=function(){var e;return e=this.queue,this.queue=[],function(){return e}},t.prototype.push=function(e){return this.queue.push(e())},t.prototype.hasAtLeast=function(){return!0},t}(b),b.isTrigger=function(e){return e instanceof b?e.sync:e instanceof c},b.fromObservable=function(e){return e instanceof b?e:e instanceof m?new b(e,!1):new s(e,!0)},_=function(){var e,t,n;return t=arguments[0],n=arguments[1],e=3<=arguments.length?ht.call(arguments,2):[],(t||n)instanceof o?t||n:new o(t,n,e)},o=function(){function e(e,t,n){var r,i,s,o;s=function(e){return I(e)?lt.flatMap(s,e):U(e)?[e]:e instanceof b?[e.obs]:[]},o=null,r=function(e){var t,n,i,s,u;n=e.internalDeps(),u=[];for(i=0,s=n.length;i0&&f.push(u),n+=2}return d.length?(d=lt.map(b.fromObservable,d),o=lt.any(d,function(e){return e.flatten})&&O(lt.map(function(e){return e.obs},d)),h=new c(_.apply(null,[e,"when"].concat(ht.call(l))),function(t){var r,i,s,u,a,l,c;return c=[],s=!1,u=function(e){var t,r,i;i=e.ixs;for(t=0,r=i.length;t0))return e.more;s=e.more,l=c.pop();for(h=0,p=f.length;h0)i[t]instanceof Function||(i[t]=function(e){return function(){return e}}(i[t])),i[t]=r(i[t]),t-=2;return at.apply(null,[e,"update",n].concat(ht.call(i),[e.when.apply(e,i).scan(n,function(e,t){return t(e)})]))},A=function(){var e;return e=1<=arguments.length?ht.call(arguments,0):[],(new i(e)).unsubscribe},i=function(){function e(e){var t,n,r;e==null&&(e=[]),this.unsubscribe=vt(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(n=0,r=e.length;n1&&e.charAt(0)==="."},e.isFieldKey=q,it=function(e,t){var n,r;return r=e.slice(1).split("."),n=lt.map(ut(t),r),function(t){var r,i;for(r=0,i=n.length;r=0)return t.splice(n,1)},fold:function(e,t,n){var r,i,s;for(i=0,s=e.length;i5?"[..]":"["+lt.map(lt.toString,e).toString()+"]":(e!=null?e.toString:void 0)!=null&&e.toString!==Object.prototype.toString?e.toString():typeof e=="object"?Z>5?"{..}":(n=function(){var n;n=[];for(r in e){if(!pt.call(e,r))continue;i=function(){try{return e[r]}catch(n){return t=n,t}}(),n.push(lt.toString(r)+":"+lt.toString(i))}return n}(),"{"+n+"}"):e}finally{Z--}}},Z=0,e._=lt,e.scheduler={setTimeout:function(e,t){return setTimeout(e,t)},setInterval:function(e,t){return setInterval(e,t)},clearInterval:function(e){return clearInterval(e)},now:function(){return(new Date).getTime()}},typeof n!="undefined"&&n!==null&&n.amd!=null?(n("lib/bacon",[],function(){return e}),this.Bacon=e):typeof module!="undefined"&&module!==null?(module.exports=e,e.Bacon=e):this.Bacon=e}.call(this),n("Map",["utils","draw","Behavior","Scale","build","UndoStack","CallbackManager","KeyManager","Canvas","data_styles","SearchIndex","lib/bacon"],function(e,t,n,r,i,s,o,u,a,f,l,c){function p(t,i,c,h,p,d,v,m,g,y){if(g===null){var b=h.get_size();g={x:-b.width,y:-b.height,width:b.width*3,height:b.height*3}}this.svg=t,this.defs=e.setup_defs(t,i),this.canvas=new a(c,g),this.setup_containers(c),this.sel=c,this.zoom_container=h,this.settings=p,this.settings.data_styles_stream.reaction.onValue(function(e){this.apply_reaction_data_to_map()}.bind(this)),this.settings.data_styles_stream.metabolite.onValue(function(e){this.apply_metabolite_data_to_map()}.bind(this)),this.reaction_data_object=f.import_and_check(d,p.data_styles.reaction,"reaction_data"),this.metabolite_data_object=f.import_and_check(v,p.data_styles.metabolite,"metabolite_data"),this.set_model(m),this.largest_ids={reactions:-1,nodes:-1,segments:-1},this.scale=new r,this.scale.connect_to_settings(this.settings),this.undo_stack=new s,this.behavior=new n(this,this.undo_stack),this.key_manager=new u,this.enable_search=y,this.search_index=new l;var w={x:0,y:0},E=1;this.beziers_enabled=!1,this.callback_manager=new o,this.nodes={},this.reactions={},this.beziers={},this.membranes=[],this.text_labels={},this.info={},this.rotation_on=!1,this.debug=!1}function d(t,n,r,s,o,u,a,f,l,c){function L(e,t){return t===undefined&&(t=0),e===undefined?t:Math.max.apply(null,Object.keys(e).map(function(e){return parseInt(e)}).concat([t]))}e.check_undefined(arguments,["map_data","svg","css","selection","zoom_container","settings","reaction_data","metabolite_data","cobra_model","enable_search"]),this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)});var p=t.canvas,d=new h(n,r,s,o,u,a,f,l,p,c);d.reactions=t.reactions,d.nodes=t.nodes,d.membranes=t.membranes,d.text_labels=t.text_labels,d.info=t.info;for(var v in d.reactions){var m=d.reactions[v];c&&d.search_index.insert("r"+v,{name:m.bigg_id,data:{type:"reaction",reaction_id:v}});for(var g in m.segments){var y=m.segments[g];y.reversibility=m.reversibility;var b=d.nodes[y.from_node_id].bigg_id;b in m.metabolites&&(y.from_node_coefficient=m.metabolites[b].coefficient);var w=d.nodes[y.to_node_id].bigg_id;w in m.metabolites&&(y.to_node_coefficient=m.metabolites[w].coefficient);var E=d.nodes[y.from_node_id],S=d.nodes[y.to_node_id];if(E["node_type"]=="metabolite"||S["node_type"]=="metabolite"){var x=e.c_plus_c(E,e.c_times_scalar(e.c_minus_c(S,E),.5));y.b1===null&&(y.b1=x),y.b2===null&&(y.b2=x)}}}if(c)for(var T in d.nodes){var N=d.nodes[T];if(N.node_type!="metabolite")continue;d.search_index.insert("n"+T,{name:N.bigg_id,data:{type:"metabolite",node_id:T}})}d.beziers=i.new_beziers_for_reactions(d.reactions),d.largest_ids.reactions=L(d.reactions),d.largest_ids.nodes=L(d.nodes),d.largest_ids.text_labels=L(d.text_labels);var C=0;for(var k in d.reactions)C=L(d.reactions[k].segments,C);return d.largest_ids.segments=C,d.apply_reaction_data_to_map(),d.apply_metabolite_data_to_map(),d}function v(e){e.append("g").attr("id","reactions"),e.append("g").attr("id","nodes"),e.append("g").attr("id","beziers"),e.append("g").attr("id","text-labels")}function m(){this.sel.select("#reactions").selectAll(".reaction").remove(),this.sel.select("#nodes").selectAll(".node").remove(),this.sel.select("#beziers").selectAll(".bezier").remove(),this.sel.select("#text-labels").selectAll(".text-label").remove()}function g(e){this.status=e,this.callback_manager.run("set_status",e)}function y(e){this.cobra_model=e,this.cobra_model!==null&&(this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.reaction),this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite))}function b(e){this.reaction_data_object=f.import_and_check(e,this.settings.data_styles.reaction,"reaction_data"),this.apply_reaction_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_reaction_data(this.reaction_data_object,this.settings.data_styles.metabolite),this.draw_all_reactions()}function w(e){this.metabolite_data_object=f.import_and_check(e,this.settings.data_styles.metabolite,"metabolite_data"),this.apply_metabolite_data_to_map(),this.cobra_model!==null&&this.cobra_model.apply_metabolite_data(this.metabolite_data_object,this.settings.data_styles.metabolite),this.draw_all_nodes()}function E(){this.reactions={},this.beziers={},this.nodes={},this.membranes=[],this.text_labels={},this.apply_reaction_data_to_map(),this.apply_metabolite_data_to_map(),this.draw_everything()}function S(){return this.reaction_data_object!==null}function x(){return this.metabolite_data_object!==null}function T(){this.draw_all_reactions(!0),this.draw_all_nodes(),this.draw_all_text_labels()}function N(e){e===undefined&&(e=!0);var t=[];for(var n in this.reactions)t.push(n);this.draw_these_reactions(t,!1),e&&this.draw_all_beziers(),this.clear_deleted_reactions(e)}function C(n,r){r===undefined&&(r=!0);var s=e.object_slice_for_ids(this.reactions,n),o=function(e){return t.update_reaction(e,this.scale,this.nodes,this.defs,this.has_reaction_data(),this.settings.no_data.reaction,this.settings.data_styles.reaction,this.behavior.reaction_label_drag)}.bind(this);e.draw_an_object(this.sel,"#reactions",".reaction",s,"reaction_id",t.create_reaction,o);if(r){var u=i.bezier_ids_for_reaction_ids(s);this.draw_these_beziers(u)}}function k(t){function n(t){e.draw_a_nested_object(t,".segment-group","segments","segment_id",null,null,function(e){e.remove()})}t===undefined&&(t=!0),e.draw_an_object(this.sel,"#reactions",".reaction",this.reactions,"reaction_id",null,n,function(e){e.remove()}),t==1&&this.clear_deleted_beziers()}function L(){var e=[];for(var t in this.nodes)e.push(t);this.draw_these_nodes(e),this.clear_deleted_nodes()}function A(n){var r=e.object_slice_for_ids(this.nodes,n),i=function(e){return t.create_node(e,this.nodes,this.reactions)}.bind(this),s=function(e){return t.update_node(e,this.scale,this.has_metabolite_data(),this.settings.data_styles.metabolite,this.behavior.selectable_click,this.behavior.node_mouseover,this.behavior.node_mouseout,this.behavior.selectable_drag,this.behavior.node_label_drag)}.bind(this);e.draw_an_object(this.sel,"#nodes",".node",r,"node_id",i,s)}function O(){e.draw_an_object(this.sel,"#nodes",".node",this.nodes,"node_id",null,null,function(e){e.remove()})}function M(){var e=[];for(var t in this.text_labels)e.push(t);this.draw_these_text_labels(e),this.clear_deleted_text_labels()}function _(n){var r=e.object_slice_for_ids(this.text_labels,n),i=function(e){return t.update_text_label(e,this.behavior.text_label_click,this.behavior.selectable_drag)}.bind(this);e.draw_an_object(this.sel,"#text-labels",".text-label",r,"text_label_id",t.create_text_label,i)}function D(){e.draw_an_object(this.sel,"#text-labels",".text-label",this.text_labels,"text_label_id",null,null,function(e){e.remove()})}function P(){var e=[];for(var t in this.beziers)e.push(t);this.draw_these_beziers(e),this.clear_deleted_beziers()}function H(n){var r=e.object_slice_for_ids(this.beziers,n),i=function(e){return t.update_bezier(e,this.beziers_enabled,this.behavior.bezier_drag,this.behavior.bezier_mouseover,this.behavior.bezier_mouseout,this.nodes,this.reactions)}.bind(this);e.draw_an_object(this.sel,"#beziers",".bezier",r,"bezier_id",t.create_bezier,i)}function B(){e.draw_an_object(this.sel,"#beziers",".bezier",this.beziers,"bezier_id",null,null,function(e){e.remove()})}function j(){this.toggle_beziers(!0)}function F(){this.toggle_beziers(!1)}function I(e){e===undefined?this.beziers_enabled=!this.beziers_enabled:this.beziers_enabled=e,this.draw_all_beziers(),this.callback_manager.run("toggle_beziers",this.beziers_enabled)}function q(){return this.apply_reaction_data_to_reactions(this.reactions)}function R(e){if(!this.has_reaction_data()){for(var t in e){var n=e[t];n.data=null,n.data_string="";for(var r in n.segments){var i=n.segments[r];i.data=null}}return!1}var s=this.reaction_data_object,o=this.settings.data_styles.reaction;for(var t in e){var n=e[t],u=n.bigg_id in s?s[n.bigg_id]:null,a=f.float_for_data(u,o),l=f.reverse_flux_for_data(u,o),c=f.text_for_data(u,o);n.data=a,n.data_string=c,n.reverse_flux=l;for(var r in n.segments){var i=n.segments[r];i.data=n.data,i.reverse_flux=n.reverse_flux}}return this.update_reaction_data_domain()}function U(){if(!this.settings.auto_domain.reaction)return!1;var t=[];for(var n in this.reactions){var r=this.reactions[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.reaction.color,s,o,u;return t.length>0?(this.settings.data_styles["reaction"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("reaction",s),!e.compare_arrays(i,s)}function z(){return this.apply_metabolite_data_to_nodes(this.nodes)}function W(e){if(!this.has_metabolite_data()){for(var t in e)e[t].data=null,e[t].data_string="";return!1}var n=this.metabolite_data_object,r=this.settings.data_styles.metabolite;for(var t in e){var i=e[t],s=i.bigg_id in n?n[i.bigg_id]:null,o=f.float_for_data(s,r),u=f.text_for_data(s,r);i.data=o,i.data_string=u}return this.update_metabolite_data_domain()}function X(){if(!this.settings.auto_domain.metabolite)return!1;var t=[];for(var n in this.nodes){var r=this.nodes[n];r.data!==null&&t.push(r.data)}var i=this.settings.domain.metabolite.color,s,o,u;return t.length>0?(this.settings.data_styles["metabolite"].indexOf("abs")!=-1&&(t=t.map(function(e){return Math.abs(e)})),o=Math.min.apply(null,t),u=Math.max.apply(null,t)):(o=0,u=0),s=[0,o,u].sort(),this.settings.set_domain("metabolite",s),!e.compare_arrays(i,s)}function V(e){var t=this.nodes[e],n={x:t.x,y:t.y};return n}function $(){var e=[];return this.sel.select("#nodes").selectAll(".selected").each(function(t){e.push(t.node_id)}),e}function J(){var e={},t=this;return this.sel.select("#nodes").selectAll(".selected").each(function(t){e[t.node_id]=this.nodes[t.node_id]}.bind(this)),e}function K(){var e=[];return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e.push(t.text_label_id)}),e}function Q(){var e={},t=this;return this.sel.select("#text-labels").selectAll(".selected").each(function(t){e[t.text_label_id]=this.text_labels[t.text_label_id]}.bind(this)),e}function G(){this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label").classed("selected",!0)}function Y(){this.sel.selectAll(".selected").classed("selected",!1)}function Z(){var e=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label");e.classed("selected",function(){return!d3.select(this).classed("selected")})}function et(e){this.deselect_text_labels();var t=this.sel.select("#nodes").selectAll(".node"),n,r;t.classed("selected",function(t){var i=String(t.node_id)==String(e);return i&&(r=t,n={x:t.x,y:t.y}),i}),this.sel.selectAll(".start-reaction-target").style("visibility","hidden"),this.callback_manager.run("select_metabolite_with_id",r,n)}function tt(e,t){var n=this.sel.selectAll("#nodes,#text-labels").selectAll(".node,.text-label"),r=this.key_manager.held_keys.shift,i;d3.select(e).attr("class").indexOf("text-label")==-1?i=e.parentNode:i=e,r?d3.select(i).classed("selected",!d3.select(i).classed("selected")):(n.classed("selected",!1),d3.select(i).classed("selected",!0));var s=this.sel.select("#nodes").selectAll(".selected"),o=0,u,a;s.each(function(e){a=e,u={x:e.x,y:e.y},o++}),this.callback_manager.run("select_selectable",o,a,u)}function nt(){var e=null,t=this,n=this.sel.select("#nodes").selectAll(".selected");return n.classed("selected",function(t,n){return n==0?(e=t,!0):!1}),e}function rt(){var e=this.sel.select("#nodes").selectAll(".node");e.classed("selected",!1)}function it(e,t){this.deselect_nodes();var n=this.sel.select("#text-labels").selectAll(".text-label");n.classed("selected",function(e){return t===e});var r=this.sel.select("#text-labels").selectAll(".selected"),i;r.each(function(e){i={x:e.x,y:e.y}}),this.callback_manager.run("select_text_label")}function st(){var e=this.sel.select("#text-labels").selectAll(".text-label");e.classed("selected",!1)}function ot(){var e=this.get_selected_nodes(),t=this.get_selected_text_labels();(Object.keys(e).length>=1||Object.keys(t).length>=1)&&this.delete_selectable(e,t,!0)}function ut(t,n,r){var s=this.segments_and_reactions_for_nodes(t),o=s.segment_objs_w_segments,u=s.reactions,a=e.clone(t),f=e.clone(o),l=e.clone(u),c=e.clone(n),h=function(e,n,i,s){this.delete_node_data(Object.keys(t)),this.delete_segment_data(i),this.delete_reaction_data(Object.keys(n)),this.delete_text_label_data(Object.keys(s)),this.has_reaction_data()&&this.update_reaction_data_domain(),this.has_metabolite_data()&&this.apply_metabolite_data_domain(),r&&(this.clear_deleted_reactions(),this.clear_deleted_nodes(),this.clear_deleted_text_labels())}.bind(this);h(t,u,o,n),this.undo_stack.push(function(){this.extend_nodes(a),this.extend_reactions(l);var s=Object.keys(l);for(var h in f){var p=f[h],d=p.segment;this.reactions[p.reaction_id].segments[p.segment_id]=d,[d.from_node_id,d.to_node_id].forEach(function(e){if(e in a)return;var t=this.nodes[e];t.connected_segments.push({reaction_id:p.reaction_id,segment_id:p.segment_id})}.bind(this));var v=p.segment_id,m=p.reaction_id,g={};g[v]=p.segment,e.extend(this.beziers,i.new_beziers_for_segments(g,m)),s.indexOf(p.reaction_id)==-1&&s.push(p.reaction_id)}if(this.has_reaction_data()){var y=this.update_reaction_data_domain();y?this.draw_all_reactions():this.draw_these_reactions(s)}else r&&this.draw_these_reactions(s);if(this.has_metabolite_data()){var y=this.update_metabolite_data_domain();r&&(y?this.draw_all_nodes():this.draw_these_nodes(Object.keys(a)))}else r&&this.draw_these_nodes(Object.keys(a));e.extend(this.text_labels,c),r&&this.draw_these_text_labels(Object.keys(c)),n=e.clone(c),t=e.clone(a),o=e.clone(f),u=e.clone(l)}.bind(this),function(){h(t,u,o,n)}.bind(this))}function at(e){e.forEach(function(e){if(this.enable_search&&this.nodes[e].node_type=="metabolite"){var t=this.search_index.remove("n"+e);t||console.warn("Could not find deleted metabolite in search index")}delete this.nodes[e]}.bind(this))}function ft(e){for(var t in e){var n=e[t],r=this.reactions[n.reaction_id];if(!(n.segment_id in r.segments))return;var s=r.segments[n.segment_id];[s.from_node_id,s.to_node_id].forEach(function(e){if(!(e in this.nodes))return;var t=this.nodes[e];t.connected_segments=t.connected_segments.filter(function(e){return e.segment_id!=n.segment_id})}.bind(this)),["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n.segment_id,e);delete this.beziers[t]}.bind(this)),delete r.segments[n.segment_id]}}function lt(e){e.forEach(function(e){var t=this.reactions[e];for(var n in t.segments)["b1","b2"].forEach(function(e){var t=i.bezier_id_for_segment_id(n,e);delete this.beziers[t]}.bind(this));delete this.reactions[e];var r=this.search_index.remove("r"+e);r||console.warn("Could not find deleted reaction in search index")}.bind(this))}function ct(e){e.forEach(function(e){delete this.text_labels[e]}.bind(this))}function ht(t,n,r){function v(e,t){this.extend_nodes(e);if(this.has_metabolite_data()){var n=this.apply_metabolite_data_to_nodes(e);n?this.draw_all_nodes():this.draw_these_nodes([t])}else this.draw_these_nodes([t])}for(var i in this.reactions)if(this.reactions[i].bigg_id==t)return console.warn("reaction is already drawn"),null;if(!this.cobra_model)return console.error("No CobraModel. Cannot build new reaction");var s=e.clone(this.cobra_model.reactions[t]);for(var o in s.metabolites){var u=s.metabolites[o],a=this.cobra_model.metabolites[o];if(u<0){var f=String(++this.largest_ids.nodes),l={x:30,y:10},c={connected_segments:[],x:n.x,y:n.y,node_is_primary:!0,label_x:n.x+l.x,label_y:n.y+l.y,name:a.name,bigg_id:o,node_type:"metabolite"},h={};h[f]=c;break}}v.apply(this,[h,f]);var p=e.clone(h),d=this;return this.undo_stack.push(function(){d.delete_node_data(Object.keys(h)),h=e.clone(p),d.clear_deleted_nodes()},function(){v.apply(d,[h,f])}),this.new_reaction_for_metabolite(t,f,r),null}function pt(t){if(this.enable_search)for(var n in t){var r=t[n];if(r.node_type!="metabolite")continue;this.search_index.insert("n"+n,{name:r.bigg_id,data:{type:"metabolite",node_id:n}})}e.extend(this.nodes,t)}function dt(t){for(var n in t){var r=t[n];this.enable_search&&this.search_index.insert("r"+n,{name:r.bigg_id,data:{type:"reaction",reaction_id:n}})}e.extend(this.reactions,t)}function vt(e,t,n){var r=this.text_labels[e].text,i=function(t,n){this.text_labels[e].text=t,n&&this.draw_these_text_labels([e])}.bind(this);i(t,n),this.undo_stack.push(function(){i(r,n)},function(){i(t,n)})}function mt(t,n,r){function v(t,n,r,i){this.extend_reactions(n),e.extend(this.beziers,r),this.delete_node_data([i]),this.extend_nodes(t);if(this.has_reaction_data()){var s=this.apply_reaction_data_to_reactions(n);s?this.draw_all_reactions():this.draw_these_reactions(Object.keys(n))}else this.draw_these_reactions(Object.keys(n));if(this.has_metabolite_data()){var s=this.apply_metabolite_data_to_nodes(t);s?this.draw_all_nodes():this.draw_these_nodes(Object.keys(t))}else this.draw_these_nodes(Object.keys(t));for(var o in t){var u=t[o];if(u.node_is_primary&&o!=i){this.select_metabolite_with_id(o);var a={x:u.x,y:u.y};this.zoom_container&&this.zoom_container.translate_off_screen(a)}}}for(var s in this.reactions)if(this.reactions[s].bigg_id==t){console.warn("reaction is already drawn");return}var o=this.nodes[n],u=this.cobra_model.reactions[t],a=i.new_reaction(t,u,this.cobra_model.metabolites,n,e.clone(o),this.largest_ids,this.cobra_model.cofactors,r),f=a.new_nodes,l=a.new_reactions,c=a.new_beziers;v.apply(this,[f,l,c,n]);var h=e.clone(f),p=e.clone(l),d=e.clone(c);this.undo_stack.push(function(){delete f[n],this.delete_node_data(Object.keys(f)),this.delete_reaction_data(Object.keys(l)),et.apply(this,[n]),f=e.clone(h),l=e.clone(p),c=e.clone(d),this.clear_deleted_nodes(),this.clear_deleted_reactions(!0)}.bind(this),function(){v.apply(this,[f,l,c,n])}.bind(this))}function gt(){var e=this.get_selected_nodes(),t=Object.keys(e)[0],n=e[t],r=this.reactions,i=this.nodes,s=[],o;i[t].connected_segments.forEach(function(e){o=[e.reaction_id];var n=r[e.reaction_id].segments[e.segment_id];s.push(n.from_node_id==t?n.to_node_id:n.from_node_id)});if(s.length!=1)return console.error("Only connected nodes with a single reaction can be selected");var u=s[0],a=[t],f=[];i[u].connected_segments.forEach(function(e){var n=r[e.reaction_id].segments[e.segment_id],s=n.from_node_id==u?n.to_node_id:n.from_node_id,o=i[s];o.node_type=="metabolite"&&s!=t&&a.push(String(s))});for(var l=0;l1)return console.error("Only connected nodes with a single reaction can be selected");for(var c in e)if(c!=t&&a.indexOf(c)==-1)return console.warn("Selected nodes are not on the same reaction");var h=[],p=a.length-1,d=i[a[p]],v=d.node_is_primary,m={x:d.x,y:d.y,label_x:d.label_x,label_y:d.label_y},g=d.connected_segments[0],y=r[g.reaction_id].segments[g.segment_id],b={b1:y.b1,b2:y.b2},w;a.forEach(function(e){var t=i[e],n=t.node_is_primary,s={x:t.x,y:t.y,label_x:t.label_x,label_y:t.label_y},o=t.connected_segments[0],u=r[o.reaction_id].segments[o.segment_id],a={b1:u.b1,b2:u.b2};t.node_is_primary=v,t.x=m.x,t.y=m.y,t.label_x=m.label_x,t.label_y=m.label_y,u.b1=b.b1,u.b2=b.b2,v=n,m=s,b=a,t.node_is_primary&&(w=e),h.push(e)});var E=i[u].connected_segments,p=E.length-1,S=[E[p]];return E.forEach(function(e,t){if(p==t)return;S.push(e)}),i[u].connected_segments=S,this.draw_these_nodes(h),this.draw_these_reactions(o),this.select_metabolite_with_id(w),null}function yt(){var e=this.get_selected_nodes(),t=this.reactions,n=this.nodes;if(Object.keys(e).length!=1)return console.error("Only one node can be selected");var r=Object.keys(e)[0],i=e[r];n[r].node_is_primary=!0;var s=[r],o=[];n[r].connected_segments.forEach(function(e){var n=t[e.reaction_id].segments[e.segment_id];o.push(n.from_node_id==r?n.to_node_id:n.from_node_id)}),o.forEach(function(e){var i=[];n[e].connected_segments.forEach(function(i){var o=t[i.reaction_id].segments[i.segment_id],u=o.from_node_id==e?o.to_node_id:o.from_node_id,a=n[u];a.node_type=="metabolite"&&u!=r&&(a.node_is_primary=!1,s.push(u))})}),this.draw_these_nodes(s)}function bt(t){var n={},r={},i={},s=this.reactions;for(var o in t){var u=t[o];u.connected_segments.forEach(function(t){var r=s[t.reaction_id],o=r.segments[t.segment_id],u=e.clone(t);u.segment=e.clone(o),n[t.segment_id]=u,t.reaction_id in i||(i[t.reaction_id]=[]),i[t.reaction_id].push(t.segment_id)})}for(var a in i){var f=s[a],l=i[a],c=!0;for(var h in f.segments)l.indexOf(h)==-1&&(c=!1);c&&(r[a]=f)}return{segment_objs_w_segments:n,reactions:r}}function g(e){var t=d3.select("body").select("#status");return t.empty()&&(t=d3.select("body").append("text").attr("id","status")),t.text(e),this}function wt(e){this._zoom_extent(e,"nodes")}function Et(e){this._zoom_extent(e,"canvas")}function St(e,t){e===undefined&&(e=t=="nodes"?.2:0),t===undefined&&(t="canvas");var n,r,i=this.get_size();e*=i.height;if(t=="nodes"){var s={x:null,y:null},o={x:null,y:null};for(var u in this.nodes){var a=this.nodes[u];s.x===null&&(s.x=a.x),s.y===null&&(s.y=a.y),o.x===null&&(o.x=a.x),o.y===null&&(o.y=a.y),s.x=Math.min(s.x,a.x),s.y=Math.min(s.y,a.y),o.x=Math.max(o.x,a.x),o.y=Math.max(o.y,a.y)}n=Math.min((i.width-e*2)/(o.x-s.x),(i.height-e*2)/(o.y-s.y)),r={x:-(s.x*n)+e+(i.width-e*2-(o.x-s.x)*n)/2,y:-(s.y*n)+e+(i.height-e*2-(o.y-s.y)*n)/2}}else{if(t!="canvas")return console.error("Did not recognize mode");n=Math.min((i.width-e*2)/this.canvas.width,(i.height-e*2)/this.canvas.height),r={x:-(this.canvas.x*n)+e+(i.width-e*2-this.canvas.width*n)/2,y:-(this.canvas.y*n)+e+(i.height-e*2-this.canvas.height*n)/2}}return this.zoom_container.go_to(n,r),null}function xt(){return this.zoom_container.get_size()}function Tt(e){var t=this.reactions[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Nt(e){var t=this.nodes[e],n=.6,r=this.get_size(),i={x:-t.label_x*n+r.width/2,y:-t.label_y*n+r.height/2};this.zoom_container.go_to(n,i)}function Ct(e){this.highlight(this.sel.selectAll("#r"+e).selectAll("text"))}function kt(e){this.highlight(this.sel.selectAll("#n"+e).selectAll("text"))}function Lt(e){this.sel.selectAll(".highlight").classed("highlight",!1),e!==null&&e.classed("highlight",!0)}function At(){e.download_json(this.map_for_export(),"saved_map")}function Ot(){var t={reactions:e.clone(this.reactions),nodes:e.clone(this.nodes),membranes:e.clone(this.membranes),text_labels:e.clone(this.text_labels),canvas:this.canvas.size_and_location()};for(var n in t.reactions){var r=t.reactions[n];delete r.data,delete r.data_string;for(var i in r.segments){var s=r.segments[i];delete s.reversibility,delete s.from_node_coefficient,delete s.to_node_coefficient,delete s.data}}for(var o in t.nodes){var u=t.nodes[o];delete u.data,delete u.data_string}return this.debug&&d3.json("map_spec.json",function(n,r){if(n){console.warn(n);return}e.check_r(t,r.spec,r.can_be_none)}),t}function Mt(){this.callback_manager.run("before_svg_export");var t=this.zoom_container.window_scale,n=this.zoom_container.window_translate,r=this.canvas.size_and_location(),i={w:this.canvas.mouse_node.attr("width"),h:this.canvas.mouse_node.attr("height"),transform:this.canvas.mouse_node.attr("transform")};this.zoom_container.go_to(1,{x:-r.x,y:-r.y},!1),this.svg.attr("width",r.width),this.svg.attr("height",r.height),this.canvas.mouse_node.attr("width","0px"),this.canvas.mouse_node.attr("height","0px"),this.canvas.mouse_node.attr("transform",null);var s=this.sel.selectAll(".multimarker-circle,.midmarker-circle").style("visibility","hidden");e.export_svg("saved_map",this.svg,!0),this.zoom_container.go_to(t,n,!1),this.svg.attr("width",null),this.svg.attr("height",null),this.canvas.mouse_node.attr("width",i.w),this.canvas.mouse_node.attr("height",i.h),this.canvas.mouse_node.attr("transform",i.transform),s.style("visibility",null),this.callback_manager.run("after_svg_export")}var h=e.make_class();return h.from_data=d,h.prototype={init:p,setup_containers:v,reset_containers:m,set_status:g,set_model:y,set_reaction_data:b,set_metabolite_data:w,clear_map:E,select_all:G,select_none:Y,invert_selection:Z,select_selectable:tt,select_metabolite_with_id:et,select_single_node:nt,deselect_nodes:rt,select_text_label:it,deselect_text_labels:st,new_reaction_from_scratch:ht,new_reaction_for_metabolite:mt,cycle_primary_node:gt,make_selected_node_primary:yt,extend_nodes:pt,extend_reactions:dt,edit_text_label:vt,delete_selected:ot,delete_selectable:ut,delete_node_data:at,delete_segment_data:ft,delete_reaction_data:lt,delete_text_label_data:ct,get_selected_node_ids:$,get_selected_nodes:J,get_selected_text_label_ids:K,get_selected_text_labels:Q,segments_and_reactions_for_nodes:bt,draw_everything:T,draw_all_reactions:N,draw_these_reactions:C,clear_deleted_reactions:k,draw_all_nodes:L,draw_these_nodes:A,clear_deleted_nodes:O,draw_all_text_labels:M,draw_these_text_labels:_,clear_deleted_text_labels:D,draw_all_beziers:P,draw_these_beziers:H,clear_deleted_beziers:B,toggle_beziers:I,hide_beziers:F,show_beziers:j,has_reaction_data:S,has_metabolite_data:x,apply_reaction_data_to_map:q,apply_reaction_data_to_reactions:R,update_reaction_data_domain:U,apply_metabolite_data_to_map:z,apply_metabolite_data_to_nodes:W,update_metabolite_data_domain:X,zoom_extent_nodes:wt,zoom_extent_canvas:Et,_zoom_extent:St,get_size:xt,zoom_to_reaction:Tt,zoom_to_node:Nt,highlight_reaction:Ct,highlight_node:kt,highlight:Lt,save:At,map_for_export:Ot,save_svg:Mt},h}),n("PlacedDiv",["utils","Map"],function(e,t){function r(e,n,r){this.div=e,r===undefined&&(r={x:0,y:0}),this.displacement=r;if(!(n instanceof t))throw new Error("Cannot set the map. It is not an instance of Map");this.map=n}function i(){return this.div.style("display")!="none"}function s(e){this.div.style("display",null);var t=this.map.zoom_container.window_translate,n=this.map.zoom_container.window_scale,r=this.map.get_size(),i=Math.max(20,Math.min(r.width-270,n*e.x+t.x-this.displacement.x)),s=Math.max(20,Math.min(r.height-40,n*e.y+t.y-this.displacement.y));this.div.style("position","absolute").style("display","block").style("left",i+"px").style("top",s+"px")}function o(){this.div.style("display","none")}var n=e.make_class();return n.prototype={init:r,is_visible:i,place:s,hide:o},n}),n("lib/complete.ly",[],function(){return function(e,t){function h(e){return l===undefined&&(l=document.createElement("span"),l.style.visibility="hidden",l.style.position="fixed",l.style.outline="0",l.style.margin="0",l.style.padding="0",l.style.border="0",l.style.left="0",l.style.whiteSpace="pre",l.style.fontSize=t.fontSize,l.style.fontFamily=t.fontFamily,l.style.fontWeight="normal",document.body.appendChild(l)),l.innerHTML=String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">"),l.getBoundingClientRect().right}t=t||{},t.fontSize=t.fontSize||"16px",t.fontFamily=t.fontFamily||"sans-serif",t.promptInnerHTML=t.promptInnerHTML||"",t.color=t.color||"#333",t.hintColor=t.hintColor||"#aaa",t.backgroundColor=t.backgroundColor||"#fff",t.dropDownBorderColor=t.dropDownBorderColor||"#aaa",t.dropDownZIndex=t.dropDownZIndex||"100",t.dropDownOnHoverBackgroundColor=t.dropDownOnHoverBackgroundColor||"#ddd";var n=document.createElement("input");n.type="text",n.spellcheck=!1,n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.color=t.color,n.style.backgroundColor=t.backgroundColor,n.style.width="100%",n.style.outline="0",n.style.border="0",n.style.margin="0",n.style.padding="0";var r=n.cloneNode();r.disabled="",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.borderColor="transparent",r.style.boxShadow="none",r.style.color=t.hintColor,n.style.backgroundColor="transparent",n.style.verticalAlign="top",n.style.position="relative";var i=document.createElement("div");i.style.position="relative",i.style.outline="0",i.style.border="0",i.style.margin="0",i.style.padding="0";var s=document.createElement("div");s.style.position="absolute",s.style.outline="0",s.style.margin="0",s.style.padding="0",s.style.border="0",s.style.fontSize=t.fontSize,s.style.fontFamily=t.fontFamily,s.style.color=t.color,s.style.backgroundColor=t.backgroundColor,s.style.top="0",s.style.left="0",s.style.overflow="hidden",s.innerHTML=t.promptInnerHTML,s.style.background="transparent";if(document.body===undefined)throw"document.body is undefined. The library was wired up incorrectly.";document.body.appendChild(s);var o=s.getBoundingClientRect().right;i.appendChild(s),s.style.visibility="visible",s.style.left="-"+o+"px",i.style.marginLeft=o+"px",i.appendChild(r),i.appendChild(n);var u=document.createElement("div");u.style.position="absolute",u.style.visibility="hidden",u.style.outline="0",u.style.margin="0",u.style.padding="0",u.style.textAlign="left",u.style.fontSize=t.fontSize,u.style.fontFamily=t.fontFamily,u.style.backgroundColor=t.backgroundColor,u.style.zIndex=t.dropDownZIndex,u.style.cursor="default",u.style.borderStyle="solid",u.style.borderWidth="1px",u.style.borderColor=t.dropDownBorderColor,u.style.overflowX="hidden",u.style.whiteSpace="pre",u.style.overflowY="scroll";var a=function(e){var n=[],r=0,i=-1,s=function(){this.style.outline="1px solid #ddd"},o=function(){this.style.outline="0"},u=function(){a.hide(),a.onmouseselection(this.__hint)},a={hide:function(){e.style.visibility="hidden"},refresh:function(i,f){e.style.visibility="hidden",r=0,e.innerHTML="";var l=window.innerHeight||document.documentElement.clientHeight,c=e.parentNode.getBoundingClientRect(),h=c.top-6,p=l-c.bottom-6;n=[];for(var d=0;d"+f[d].substring(i.length)+"",n.push(v),e.appendChild(v)}if(n.length===0)return;if(n.length===1&&i===n[0].__hint)return;if(n.length<2)return;a.highlight(0),h>p*3?(e.style.maxHeight=h+"px",e.style.top="",e.style.bottom="100%"):(e.style.top="100%",e.style.bottom="",e.style.maxHeight=p+"px"),e.style.visibility="visible"},highlight:function(e){i!=-1&&n[i]&&(n[i].style.backgroundColor=t.backgroundColor),n[e].style.backgroundColor=t.dropDownOnHoverBackgroundColor,i=e},move:function(t){return e.style.visibility==="hidden"?"":r+t===-1||r+t===n.length?n[r].__hint:(r+=t,a.highlight(r),n[r].__hint)},onmouseselection:function(){}};return a},f=a(u);f.onmouseselection=function(e){n.value=r.value=c+e,p.onChange(n.value),d=n.value,setTimeout(function(){n.focus()},0)},i.appendChild(u),e.appendChild(i);var l,c,p={onArrowDown:function(){},onArrowUp:function(){},onEnter:function(){},onTab:function(){},onChange:function(){p.repaint()},startFrom:0,options:[],wrapper:i,input:n,hint:r,dropDown:u,prompt:s,setText:function(e){r.value=e,n.value=e},getText:function(){return n.value},hideDropDown:function(){f.hide()},repaint:function(){var e=n.value,t=p.startFrom,i=p.options,s=i.length,o=e.substring(t);c=e.substring(0,t),r.value="";for(var a=0;a0){f.hide(),n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==13){if(r.value.length==0)p.onEnter();else{var s=u.style.visibility=="hidden";f.hide();if(s){r.value=n.value,n.focus(),p.onEnter();return}n.value=r.value;var i=d!=n.value;d=n.value,i&&p.onChange(n.value)}return}if(t==40){var o=f.move(1);o==""&&p.onArrowDown(),r.value=c+o;return}if(t==38){var o=f.move(-1);o==""&&p.onArrowUp(),r.value=c+o,e.preventDefault(),e.stopPropagation();return}r.value=""};return n.addEventListener?n.addEventListener("keydown",m,!1):n.attachEvent("onkeydown",m),p}}),n("ZoomContainer",["utils","CallbackManager"],function(e,t){function r(e,n,r){this.zoom_on=!0,this.initial_zoom=1,this.window_translate={x:0,y:0},this.window_scale=1,this.callback_manager=new t,this.size_container=n,e.select("#zoom-container").remove();var i=e.append("g").attr("id","zoom-container");this.zoomed_sel=i.append("g");var s=function(e,t){e.zoom_on&&(e.zoomed_sel.attr("transform","translate("+t.translate+")"+"scale("+t.scale+")"),e.window_translate={x:t.translate[0],y:t.translate[1]},e.window_scale=t.scale,e.callback_manager.run("zoom"))},o=this;this.zoom_behavior=d3.behavior.zoom().on("zoom",function(){s(o,d3.event)}),i.call(this.zoom_behavior),(r=="none"||r=="pan")&&i.on("mousewheel.zoom",null).on("DOMMouseScroll.zoom",null).on("wheel.zoom",null).on("dblclick.zoom",null);if(r=="pan"){var u=function(){var e=d3.event,t=.5;e.stopPropagation(),e.preventDefault(),e.returnValue=!1,this.go_to(this.window_scale,{x:this.window_translate.x-(e.wheelDeltaX!==undefined?-e.wheelDeltaX/1.5:e.deltaX)*t,y:this.window_translate.y-(e.wheelDeltaY!==undefined?-e.wheelDeltaY/1.5:e.deltaY)*t},!1)}.bind(this);i.on("mousewheel.escher",u),i.on("DOMMouseScroll.escher",u),i.on("wheel.escher",u)}this.saved_scale=null,this.saved_translate=null}function i(t){t===undefined?this.zoom_on=!this.zoom_on:this.zoom_on=t,this.zoom_on?(this.saved_scale!==null&&(this.zoom_behavior.scale(this.saved_scale),this.saved_scale=null),this.saved_translate!==null&&(this.zoom_behavior.translate(this.saved_translate),this.saved_translate=null),this.zoomed_sel.classed("cursor-grab",!0).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",function(e){e.classed("cursor-grab",!1).classed("cursor-grabbing",!0)}.bind(null,this.zoomed_sel)).on("mouseup.cursor",function(e){e.classed("cursor-grab",!0).classed("cursor-grabbing",!1)}.bind(null,this.zoomed_sel))):(this.saved_scale===null&&(this.saved_scale=e.clone(this.zoom_behavior.scale())),this.saved_translate===null&&(this.saved_translate=e.clone(this.zoom_behavior.translate())),this.zoomed_sel.style("cursor",null).classed("cursor-grab",!1).classed("cursor-grabbing",!1),this.zoomed_sel.on("mousedown.cursor",null),this.zoomed_sel.on("mouseup.cursor",null))}function s(t,n,r){e.check_undefined(arguments,["scale","translate"]),r===undefined&&(r=!0);if(!t)throw new Error("Bad scale value");if(!!n&&"x"in n&&"y"in n&&!isNaN(n.x)&&!isNaN(n.y)){this.zoom_behavior.scale(t),this.window_scale=t,this.saved_scale!==null&&(this.saved_scale=t);var i=[n.x,n.y];this.zoom_behavior.translate(i),this.window_translate=n,this.saved_translate!==null&&(this.saved_translate=i);var s=r?this.zoomed_sel.transition():this.zoomed_sel;return s.attr("transform","translate("+this.window_translate.x+","+this.window_translate.y+")"+"scale("+this.window_scale+")"),this.callback_manager.run("go_to"),null}return console.error("Bad translate value")}function o(t){var n=this.get_size(),r={x:n.width/2-((n.width/2-this.window_translate.x)*t+this.window_translate.x),y:n.height/2-((n.height/2-this.window_translate.y)*t+this.window_translate.y)};this.go_to(this.window_scale*t,e.c_plus_c(this.window_translate,r),!0)}function u(){this.zoom_by(1.5)}function a(){this.zoom_by(.667)}function f(){return{width:parseInt(this.size_container.style("width"),10),height:parseInt(this.size_container.style("height"),10)}}function l(e){var t=120,n=this.get_size(),r={x:{min:-this.window_translate.x/this.window_scale+t/this.window_scale,max:-this.window_translate.x/this.window_scale+(n.width-t)/this.window_scale},y:{min:-this.window_translate.y/this.window_scale+t/this.window_scale,max:-this.window_translate.y/this.window_scale+(n.height-t)/this.window_scale}};e.xr.x.max&&(this.window_translate.x=this.window_translate.x-(e.x-r.x.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate)),e.yr.y.max&&(this.window_translate.y=this.window_translate.y-(e.y-r.y.max)*this.window_scale,this.go_to(this.window_scale,this.window_translate))}function c(){this.go_to(1,{x:0,y:0})}var n=e.make_class();return n.prototype={init:r,toggle_zoom:i,go_to:s,zoom_by:o,zoom_in:u,zoom_out:a,get_size:f,translate_off_screen:l,reset:c},n}),n("DirectionArrow",["utils"],function(e){function n(e){function t(){return"M0 -5 L0 5 L20 5 L20 10 L30 0 L20 -10 L20 -5 Z"}this.arrow_container=e.append("g").attr("id","direction-arrow-container").attr("transform","translate(0,0)rotate(0)"),this.arrow=this.arrow_container.append("path").classed("direction-arrow",!0).attr("d",t()).style("visibility","hidden").attr("transform","translate(30,0)scale(2.5)"),this.sel=e,this.center={x:0,y:0},this._setup_drag(),this.dragging=!1,this.is_visible=!1,this.show()}function r(e){this.center=e;var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+e.x+","+e.y+")rotate("+t.rotate+")")}function i(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")rotate("+e+")")}function s(e){var t=d3.transform(this.arrow_container.attr("transform"));this.arrow_container.attr("transform","translate("+t.translate+")"+"rotate("+(t.rotate+e)+")")}function o(){return d3.transform(this.arrow_container.attr("transform")).rotate}function u(e){e===undefined?this.is_visible=!this.is_visible:this.is_visible=e,this.arrow.style("visibility",this.is_visible?"visible":"hidden")}function a(){this.toggle(!0)}function f(){this.toggle(!1)}function l(){this.set_rotation(0)}function c(){this.set_rotation(90)}function h(){this.set_rotation(180)}function p(){this.set_rotation(270)}function d(){var t=d3.behavior.drag().on("dragstart",function(e){d3.event.sourceEvent.stopPropagation(),this.dragging=!0}.bind(this)).on("drag.direction_arrow",function(t){var n={x:d3.event.dx,y:d3.event.dy},r={x:d3.mouse(this.sel.node())[0],y:d3.mouse(this.sel.node())[1]},i=e.angle_for_event(n,r,this.center);this.displace_rotation(e.to_degrees(i))}.bind(this)).on("dragend",function(e){window.setTimeout(function(){this.dragging=!1}.bind(this),200)}.bind(this));this.arrow_container.call(t)}var t=e.make_class();return t.prototype={init:n,set_location:r,set_rotation:i,displace_rotation:s,get_rotation:o,toggle:u,show:a,hide:f,right:l,left:h,up:p,down:c,_setup_drag:d},t}),n("BuildInput",["utils","PlacedDiv","lib/complete.ly","Map","ZoomContainer","CallbackManager","draw","DirectionArrow"],function(e,t,n,r,i,s,o,u){function f(e,s,o){var a=e.append("div").attr("id","rxn-input");this.placed_div=t(a,s,{x:240,y:0}),this.placed_div.hide();var f=n(a.node(),{backgroundColor:"#eee"});d3.select(f.input).on("input",function(){this.value=this.value.replace(" ","").replace("\\","").replace("<","")}),this.completely=f,a.append("button").attr("class","button input-close-button").text("×").on("click",function(){this.hide_dropdown()}.bind(this));if(!(s instanceof r))throw new Error("Cannot set the map. It is not an instance of Map");this.map=s;var l=90;this.direction_arrow=new u(s.sel),this.direction_arrow.set_rotation(l),this.setup_map_callbacks(s);if(!(o instanceof i))throw new Error("Cannot set the zoom_container. It is not an instance of ZoomContainer");this.zoom_container=o,this.setup_zoom_callbacks(o),this.toggle(!1),this.target_coords=null}function l(e){e.callback_manager.set("select_metabolite_with_id.input",function(e,t){this.is_active&&this.reload(e,t,!1),this.hide_target()}.bind(this)),e.callback_manager.set("select_selectable.input",function(e,t,n){this.hide_target(),e==1&&this.is_active&&n?this.reload(t,n,!1):this.toggle(!1)}.bind(this)),e.callback_manager.set("before_svg_export",function(){this.direction_arrow.hide(),this.hide_target()}.bind(this))}function c(e){e.callback_manager.set("zoom.input",function(){this.is_active&&this.place_at_selected()}.bind(this))}function h(){return this.placed_div.is_visible()}function p(e){e===undefined?this.is_active=!this.is_active:this.is_active=e,this.is_active?(this.toggle_start_reaction_listener(!0),this.target_coords!==null?this.show_dropdown(this.target_coords):this.reload_at_selected(),this.map.set_status("Click on the canvas or an existing metabolite"),this.direction_arrow.show(),this.escape=this.map.key_manager.add_escape_listener(function(){this.hide_dropdown()}.bind(this))):(this.toggle_start_reaction_listener(!1),this.placed_div.hide(),this.completely.input.blur(),this.completely.hideDropDown(),this.map.set_status(null),this.direction_arrow.hide(),this.escape&&this.escape.clear(),this.escape=null)}function d(e){this.placed_div.show(),this.completely.input.blur(),this.completely.repaint(),this.completely.setText(""),this.completely.input.focus()}function v(){this.placed_div.hide(),this.completely.hideDropDown()}function m(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return;var t={x:e.x,y:e.y};this.place(t)}function g(e){this.placed_div.place(e),this.direction_arrow.set_location(e),this.direction_arrow.show()}function y(){this.map.deselect_text_labels();var e=this.map.select_single_node();if(e==null)return!1;var t={x:e.x,y:e.y};return this.reload(e,t,!1),!0}function b(t,n,r){function w(e,t){for(var n in t)if(t[n].bigg_id==e)return!0;return!1}t===undefined&&!r&&console.error("No selected node, and not starting from scratch"),this.place(n),this.completely.input.blur(),this.completely.repaint();if(this.map.cobra_model===null){this.completely.setText("Cannot add: No model.");return}var i=[],s=this.map.cobra_model.reactions,o=this.map.cobra_model.metabolites,u=this.map.reactions,a=this.map.has_reaction_data(),f=this.map.reaction_data,l=this.map.reaction_data_styles;for(var c in s){var h=s[c];if(w(c,u))continue;for(var p in h.metabolites)if(r||p==t.bigg_id){if(c in i)continue;a?i[c]={reaction_data:h.data,string:c+": "+h.data_string}:i[c]={string:c}}}var d=[],v=e.make_array(i,"reaction_abbreviation");a?v.sort(function(e,t){return Math.abs(t.reaction_data)-Math.abs(e.reaction_data)}):v.sort(function(e,t){return e.string.toLowerCase()Filter by organism
-
-

Model

-
-
-

Map

-
@@ -67,6 +67,7 @@

Options

+

FAQ

    @@ -89,10 +90,10 @@

    FAQ

    + {% if web_version %} {% else %} {% endif %} - {% endblock %} diff --git a/escher/urls.py b/escher/urls.py index c98e9aed..e86c4498 100644 --- a/escher/urls.py +++ b/escher/urls.py @@ -7,7 +7,7 @@ organism_download = "https://zakandrewking.github.io/escher/organisms/" organism_download_local = "organisms/" download = "https://zakandrewking.github.io/escher/" -download_local = "/" +download_local = "" escher_home = "https://zakandrewking.github.io/escher/" github = "https://github.com/zakandrewking/escher" diff --git a/spec/javascripts/utilsSpec.js b/spec/javascripts/utilsSpec.js index a063ba33..ad0cbd95 100644 --- a/spec/javascripts/utilsSpec.js +++ b/spec/javascripts/utilsSpec.js @@ -28,21 +28,29 @@ describe('utils', function() { expect(utils.check_for_parent_tag(sel, 'svg')).toBe(false); }); + it('test_name_to_url', function() { + var url = utils.name_to_url('e_coli:iJO1366', 'https://zakandrewking.github.io/escher/', 'model'); + expect(url).toEqual('https://zakandrewking.github.io/escher/organisms/e_coli/models/iJO1366.json'); + + var url = utils.name_to_url('e_coli:iJO1366:central_metabolism', '', 'map'); + expect(url).toEqual('organisms/e_coli/models/iJO1366/maps/central_metabolism.json'); + }); + it('parse_url_components', function() { - var url = '?map_name=iJO1366_central_metabolism&model_name=iJO1366', + var url = '?map_name=e_coli:iJO1366:central_metabolism&model_name=e_coli:iJO1366', the_window = { location: { search: url } }; var options = utils.parse_url_components(the_window); - expect(options).toEqual({ map_name: 'iJO1366_central_metabolism', - model_name: 'iJO1366' }); + expect(options).toEqual({ map_name: 'e_coli:iJO1366:central_metabolism', + model_name: 'e_coli:iJO1366' }); options = { a: 'b', model_name: 'old_model_name' }; - options = utils.parse_url_components(the_window, options, 'http://host1/', 'http://host2/'); - expect(options).toEqual({ map_name: 'iJO1366_central_metabolism', - model_name: 'iJO1366', - map_path: 'http://host1/iJO1366_central_metabolism.json', - cobra_model_path: 'http://host2/iJO1366.json', + options = utils.parse_url_components(the_window, options, 'http://host/'); + expect(options).toEqual({ map_name: 'e_coli:iJO1366:central_metabolism', + model_name: 'e_coli:iJO1366', + map_path: 'http://host/organisms/e_coli/models/iJO1366/maps/central_metabolism.json', + cobra_model_path: 'http://host/organisms/e_coli/models/iJO1366.json', a: 'b' }); }); }); From afb16015f934dcf39271e89529785cdd8152ef59 Mon Sep 17 00:00:00 2001 From: Zak King Date: Tue, 9 Sep 2014 16:24:20 -0700 Subject: [PATCH 27/33] merged in setup.py from gh-pages --- setup.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 41821128..2bb7a3f7 100644 --- a/setup.py +++ b/setup.py @@ -27,8 +27,12 @@ def finalize_options(self): def run(self): call(['rm', '-rf', join(directory, 'build')]) call(['rm', '-rf', join(directory, 'dist')]) + # remove lib files for f in glob(join(directory, 'escher/lib/escher.*.js')): os.remove(f) + # remove site files + for f in glob(join(directory, '*.html')): + os.remove(f) print 'done cleaning' class JSBuildCommand(Command): @@ -43,7 +47,25 @@ def run(self): 'out=escher/lib/%s'%escher, 'optimize=none']) call([join(directory, 'bin/r.js'), '-o', 'escher/js/build/build.js', 'out=escher/lib/%s'%escher_min, 'optimize=uglify']) - print 'done building' + print 'done building js' + +class BuildGHPagesCommand(Command): + description = "Custom build command that generates static site, and copies escher libs" + user_options = [] + def initialize_options(self): + pass + def finalize_options(self): + pass + def run(self): + # copy files to top level + call(['cp', join('escher/lib/', escher), '.']) + call(['cp', join('escher/lib/', escher_min), '.']) + call(['cp', join('escher/lib/', escher), 'escher.js']) + call(['cp', join('escher/lib/', escher_min), 'escher.min.js']) + # generate the static site + call(['python', 'escher/static_site.py']) + call(['python', 'escher/generate_index.py']) + print 'done building gh-pages' class TestCommand(Command): description = "Custom test command that runs pytest and jasmine" @@ -70,4 +92,5 @@ def run(self): 'resources/*']}, cmdclass={'clean': CleanCommand, 'buildjs': JSBuildCommand, + 'buildgh': BuildGHPagesCommand, 'test': TestCommand}) From 31d9339e5b7fda0a8d46b99524810442ee91417b Mon Sep 17 00:00:00 2001 From: Zak King Date: Wed, 10 Sep 2014 17:17:14 -0700 Subject: [PATCH 28/33] Small fixes. - Remove illegal characters from embedded_css - Lenient single-origin policy - More specific css definitions to avoid overlap with IPython notebook --- escher/css/builder-embed.css | 6 +++--- escher/plots.py | 6 +++++- escher/server.py | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/escher/css/builder-embed.css b/escher/css/builder-embed.css index 2fec890e..053b6e8b 100644 --- a/escher/css/builder-embed.css +++ b/escher/css/builder-embed.css @@ -36,17 +36,17 @@ fill: none; stroke: rgb(50, 50, 50); } -.selected .node-circle{ +g.selected .node-circle{ stroke-width: 3px; stroke: rgb(20, 113, 199); } -.selected .label { +g.selected .label { fill: rgb(20, 113, 199); } .metabolite-circle { stroke: rgb(162, 69, 16); } -.selected .metabolite-circle { +g.selected .metabolite-circle { stroke: rgb(5, 2, 0); } .segment { diff --git a/escher/plots.py b/escher/plots.py index 85ee5a89..bde47a65 100644 --- a/escher/plots.py +++ b/escher/plots.py @@ -172,7 +172,11 @@ def __init__(self, map_name=None, map_json=None, model_name=None, self.reaction_data = reaction_data self.metabolite_data = metabolite_data self.local_host = local_host.strip(os.sep) - self.embedded_css = embedded_css + # remove illegal characters from css + try: + self.embedded_css = embedded_css.replace('\n', '') + except AttributeError: + self.embedded_css = None # make the unique id self.generate_id() diff --git a/escher/server.py b/escher/server.py index 62ffbd89..abe0f584 100644 --- a/escher/server.py +++ b/escher/server.py @@ -55,6 +55,7 @@ def serve_path(self, path): def serve(self, data): if (NO_CACHE): self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') + self.set_header('Access-Control-Allow-Origin', '*') self.write(data) self.finish() From b02035adfcb76f171e7c0db7c3a2387458d46171 Mon Sep 17 00:00:00 2001 From: Zak King Date: Wed, 10 Sep 2014 18:23:06 -0700 Subject: [PATCH 29/33] Major fix to URL management IN PROGRESS --- docs/notebooks/development.ipynb | 123 +++++++-- docs/notebooks/json_models_in_cobrapy.ipynb | 23 +- docs/notebooks/multiple_maps.ipynb | 267 +++++++++++--------- escher/plots.py | 35 ++- escher/server.py | 12 +- escher/static_site.py | 12 +- escher/tests/test_urls.py | 17 +- escher/urls.py | 55 ++-- 8 files changed, 324 insertions(+), 220 deletions(-) diff --git a/docs/notebooks/development.ipynb b/docs/notebooks/development.ipynb index 8a3cb689..923019d7 100644 --- a/docs/notebooks/development.ipynb +++ b/docs/notebooks/development.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:323f299900cf8984455ef883a20a75455f9f1e5d5f3bf4492d0ee55187182452" + "signature": "sha256:0cb9e29d59f017a552c07796914d47cca942abb385e9329791681833c8ff28cc" }, "nbformat": 3, "nbformat_minor": 0, @@ -21,7 +21,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 5 + "prompt_number": 4 }, { "cell_type": "code", @@ -29,16 +29,19 @@ "input": [ "with open(os.path.abspath('../../escher/example_data/reaction_data_iJO1366.json'), 'r') as f:\n", " reaction_data = json.load(f)\n", - "b = escher.Builder(map_name='iJO1366_central_metabolism',\n", - " model_name='iJO1366',\n", + "with open(os.path.abspath('../../escher/css/builder-embed.css'), 'r') as f:\n", + " css = f.read()\n", + "b = escher.Builder(map_name='e_coli:iJO1366:central_metabolism',\n", + " model_name='e_coli:iJO1366',\n", " reaction_data=reaction_data,\n", - " local_host='http://localhost:7778')\n", + " embedded_css=css,\n", + " local_host='http://localhost:7779')\n", "b.set_reaction_color_range(['grey', 'pink', 'blue'])" ], "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 6 + "prompt_number": 5 }, { "cell_type": "code", @@ -58,15 +61,20 @@ " \n", " \n", "\n", - " \n", - " \n", + " \n", + " \n", "\n", "\n", "\n", - "
    \n", + "
    \n", "\n", " \n", " \n", - " \n", - "\n", - " \n", - " \n", - "\n", - "\n", - "\n", - "
    \n", - "\n", - " \n", - " \n" - ], - "metadata": {}, - "output_type": "pyout", - "prompt_number": 9, - "text": [ - "" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "with open(os.path.join(d, 'escher/example_data/reaction_data_iJO1366.json')) as f:\n", - " reaction_data = json.load(f)\n", - "b2 = escher.Builder(model_name='iJO1366', map_name='iJO1366_central_metabolism',\n", - " reaction_data=reaction_data)\n", - "b2.display_in_notebook()" - ], - "language": "python", - "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ - "/Users/zaking/repos/escher/escher/plots.py:182 UserWarning: Model \"iJO1366\" not in cache. Attempting download from https://zakandrewking.github.io/escher/\n" + "/Users/zaking/www/escher-private/escher/plots.py:268: UserWarning: Map \"e_coli:iJO1366:central_metabolism\" not in cache. Attempting download from https://zakandrewking.github.io/escher\n", + " warn(map_not_cached)\n" ] }, { @@ -149,15 +71,20 @@ " \n", " \n", "\n", - " \n", + " \n", " \n", "\n", "\n", "\n", - "
    \n", + "
    \n", "\n", " \n", " \n", " \n", "\n", - " \n", - " \n", + " \n", + " \n", "\n", "\n", "\n", - "
    \n", + "
    \n", "\n", " \n", " \n", "\n", " \n", - " \n", + " \n", "\n", "\n", "\n", - "
    \n", + "
    \n", "\n", " \n", " \n", "\n", " \n", - " \n", + " \n", "\n", "\n", "\n", - "
    \n", + "
    \n", "\n", " \n", " \n", "\n", " \n", - " \n", + " \n", "\n", "\n", "\n", - "
    \n", + "
    \n", "\n", " \n", "