src/build.js
/**
 * 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.
 */
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.
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 .
function rotate_nodes (selected_nodes, reactions, beziers, angle, center) {
  var rotate_around = function (coord) {
    if (coord === null) {
      return null
    }
    return utils.rotate_coords(coord, angle, center)
  }
  var updated_node_ids = [], updated_reaction_ids = []
  for (var node_id in selected_nodes) {
    var node = selected_nodes[node_id],
    displacement = rotate_around({ x: node.x, y: node.y }),
    updated = move_node_and_labels(node, reactions,
                                   displacement)
    node.connected_segments.map(function (segment_obj) {
      var reaction = reactions[segment_obj.reaction_id]
      if (reaction === undefined) return
      var segment_id = segment_obj.segment_id
      var segment = reaction.segments[segment_id]
      if (segment.to_node_id==node_id && segment.b2) {
        var displacement = rotate_around(segment.b2)
        var 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 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
      }
    })
    updated_reaction_ids = utils.unique_concat([updated_reaction_ids,
                                                updated.reaction_ids])
    updated_node_ids.push(node_id)
  }
  return { node_ids: updated_node_ids,
           reaction_ids: updated_reaction_ids }
}
function rotate_nodes ( selected_nodes , reactions , beziers , angle , center ) { var rotate_around = function ( coord ) { if ( coord === null ) { return null } return utils . rotate_coords ( coord , angle , center ) } var updated_node_ids = [ ] , updated_reaction_ids = [ ] for ( var node_id in selected_nodes ) { var node = selected_nodes [ node_id ] , displacement = rotate_around ( { x : node . x , y : node . y } ) , updated = move_node_and_labels ( node , reactions , displacement ) node . connected_segments . map ( function ( segment_obj ) { var reaction = reactions [ segment_obj . reaction_id ] if ( reaction === undefined ) return var segment_id = segment_obj . segment_id var segment = reaction . segments [ segment_id ] if ( segment . to_node_id == node_id && segment . b2 ) { var displacement = rotate_around ( segment . b2 ) var 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 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 } } ) updated_reaction_ids = utils . unique_concat ( [ updated_reaction_ids , updated . reaction_ids ] ) updated_node_ids . push ( node_id ) } return { node_ids : updated_node_ids , reaction_ids : updated_reaction_ids } }
Rotate the nodes around center.
Rotate the nodes around center .
// recalculate: node // rotation distance // move the node // move the bezier points // If the reaction was not passed in the reactions argument, then ignore // rotate the beziers