escher.js
/**
 * Calculate metabolite coordinates for a new reaction metabolite.
 */
Calculate metabolite coordinates for a new reaction metabolite.
Calculate metabolite coordinates for a new reaction metabolite .
function calculate_new_metabolite_coordinates (met, primary_index, main_axis,
                                               center, dis, is_reversed) {
  var displacement = main_axis[0]
  main_axis = [ utils.c_minus_c(main_axis[0], displacement),
                utils.c_minus_c(main_axis[1], displacement) ]
  center = utils.c_minus_c(center, displacement)
  var w = 80 
  var b1_strength = 0.4
  var b2_strength = 0.25
  var w2 = w * 0.3 
  var secondary_dis = 50 
  var secondary_w = 20 
  var num_slots = met.count - 1
  var ds
  var draw_at_index
  var r
  if (met.is_primary) { 
    ds = 20
  } else { 
    ds = 10
    if (met.index > primary_index) draw_at_index = met.index - 1
    else draw_at_index = met.index
  }
  var de = dis - ds 
  var reaction_axis = [ { x: ds, y: 0 },
                        { x: de, y: 0 } ]
  var end
  var circle
  var b1
  var b2
  if (((met.coefficient < 0) !== is_reversed) && met.is_primary) { 
    end = {
      x: reaction_axis[0].x,
      y: reaction_axis[0].y
    }
    b1 = {
      x: center.x * (1 - b1_strength) + reaction_axis[0].x * b1_strength,
      y: center.y * (1 - b1_strength) + reaction_axis[0].y * b1_strength
    }
    b2 = {
      x: center.x * b2_strength + end.x * (1 - b2_strength),
      y: center.y * b2_strength + end.y * (1 - b2_strength)
    }
    circle = {
      x: main_axis[0].x,
      y: main_axis[0].y
    }
  } else if ((met.coefficient < 0) !== is_reversed) {
    end = {
      x: reaction_axis[0].x + _met_secondary_disp(secondary_w, secondary_dis,
                                                  draw_at_index, num_slots),
      y: reaction_axis[0].y + _met_index_disp(w2, draw_at_index, num_slots)
    }
    b1 = {
      x: center.x * (1 - b1_strength) + reaction_axis[0].x * b1_strength,
      y: center.y * (1 - b1_strength) + reaction_axis[0].y * b1_strength
    }
    b2 = {
      x: center.x * b2_strength + end.x * (1 - b2_strength),
      y: center.y * b2_strength + end.y * (1 - b2_strength)
    }
    circle = {
      x: main_axis[0].x + _met_secondary_disp (secondary_w, secondary_dis,
                                               draw_at_index, num_slots),
      y: main_axis[0].y + _met_index_disp(w, draw_at_index, num_slots)
    }
  } else if (((met.coefficient > 0) !== is_reversed) && met.is_primary) {        
    end = {
      x: reaction_axis[1].x,
      y: reaction_axis[1].y
    }
    b1 = {
      x: center.x * (1 - b1_strength) + reaction_axis[1].x * b1_strength,
      y: center.y * (1 - b1_strength) + reaction_axis[1].y * b1_strength
    }
    b2 = {
      x: center.x*b2_strength + end.x*(1-b2_strength),
      y: center.y*b2_strength + end.y*(1-b2_strength)
    }
    circle = {
      x: main_axis[1].x,
      y: main_axis[1].y
    }
  } else if ((met.coefficient > 0) !== is_reversed) {
    end = {
      x: reaction_axis[1].x - _met_secondary_disp (secondary_w, secondary_dis,
                                                   draw_at_index, num_slots),
      y: reaction_axis[1].y + _met_index_disp(w2, draw_at_index, num_slots)
    }
    b1 = {
      x: center.x * (1 - b1_strength) + reaction_axis[1].x * b1_strength,
      y: center.y * (1 - b1_strength) + reaction_axis[1].y * b1_strength
    }
    b2 = {
      x: center.x*b2_strength + end.x*(1-b2_strength),
      y: center.y*b2_strength + end.y*(1-b2_strength)
    }
    circle = {
      x: main_axis[1].x - _met_secondary_disp (secondary_w, secondary_dis,
                                               draw_at_index, num_slots),
      y: main_axis[1].y + _met_index_disp(w, draw_at_index, num_slots)
    }
  }
  return {
    b1: utils.c_plus_c(displacement, b1),
    b2: utils.c_plus_c(displacement, b2),
    circle: utils.c_plus_c(displacement, circle)
  }
}
function calculate_new_metabolite_coordinates ( met , primary_index , main_axis , center , dis , is_reversed ) { var displacement = main_axis [ 0 ] main_axis = [ utils . c_minus_c ( main_axis [ 0 ] , displacement ) , utils . c_minus_c ( main_axis [ 1 ] , displacement ) ] center = utils . c_minus_c ( center , displacement ) var w = 80 var b1_strength = 0.4 var b2_strength = 0.25 var w2 = w * 0.3 var secondary_dis = 50 var secondary_w = 20 var num_slots = met . count - 1 var ds var draw_at_index var r if ( met . is_primary ) { ds = 20 } else { ds = 10 if ( met . index > primary_index ) draw_at_index = met . index - 1 else draw_at_index = met . index } var de = dis - ds var reaction_axis = [ { x : ds , y : 0 } , { x : de , y : 0 } ] var end var circle var b1 var b2 if ( ( ( met . coefficient < 0 ) !== is_reversed ) && met . is_primary ) { end = { x : reaction_axis [ 0 ] . x , y : reaction_axis [ 0 ] . y } b1 = { x : center . x * ( 1 - b1_strength ) + reaction_axis [ 0 ] . x * b1_strength , y : center . y * ( 1 - b1_strength ) + reaction_axis [ 0 ] . y * b1_strength } b2 = { x : center . x * b2_strength + end . x * ( 1 - b2_strength ) , y : center . y * b2_strength + end . y * ( 1 - b2_strength ) } circle = { x : main_axis [ 0 ] . x , y : main_axis [ 0 ] . y } } else if ( ( met . coefficient < 0 ) !== is_reversed ) { end = { x : reaction_axis [ 0 ] . x + _met_secondary_disp ( secondary_w , secondary_dis , draw_at_index , num_slots ) , y : reaction_axis [ 0 ] . y + _met_index_disp ( w2 , draw_at_index , num_slots ) } b1 = { x : center . x * ( 1 - b1_strength ) + reaction_axis [ 0 ] . x * b1_strength , y : center . y * ( 1 - b1_strength ) + reaction_axis [ 0 ] . y * b1_strength } b2 = { x : center . x * b2_strength + end . x * ( 1 - b2_strength ) , y : center . y * b2_strength + end . y * ( 1 - b2_strength ) } circle = { x : main_axis [ 0 ] . x + _met_secondary_disp ( secondary_w , secondary_dis , draw_at_index , num_slots ) , y : main_axis [ 0 ] . y + _met_index_disp ( w , draw_at_index , num_slots ) } } else if ( ( ( met . coefficient > 0 ) !== is_reversed ) && met . is_primary ) { end = { x : reaction_axis [ 1 ] . x , y : reaction_axis [ 1 ] . y } b1 = { x : center . x * ( 1 - b1_strength ) + reaction_axis [ 1 ] . x * b1_strength , y : center . y * ( 1 - b1_strength ) + reaction_axis [ 1 ] . y * b1_strength } b2 = { x : center . x * b2_strength + end . x * ( 1 - b2_strength ) , y : center . y * b2_strength + end . y * ( 1 - b2_strength ) } circle = { x : main_axis [ 1 ] . x , y : main_axis [ 1 ] . y } } else if ( ( met . coefficient > 0 ) !== is_reversed ) { end = { x : reaction_axis [ 1 ] . x - _met_secondary_disp ( secondary_w , secondary_dis , draw_at_index , num_slots ) , y : reaction_axis [ 1 ] . y + _met_index_disp ( w2 , draw_at_index , num_slots ) } b1 = { x : center . x * ( 1 - b1_strength ) + reaction_axis [ 1 ] . x * b1_strength , y : center . y * ( 1 - b1_strength ) + reaction_axis [ 1 ] . y * b1_strength } b2 = { x : center . x * b2_strength + end . x * ( 1 - b2_strength ) , y : center . y * b2_strength + end . y * ( 1 - b2_strength ) } circle = { x : main_axis [ 1 ] . x - _met_secondary_disp ( secondary_w , secondary_dis , draw_at_index , num_slots ) , y : main_axis [ 1 ] . y + _met_index_disp ( w , draw_at_index , num_slots ) } } return { b1 : utils . c_plus_c ( displacement , b1 ) , b2 : utils . c_plus_c ( displacement , b2 ) , circle : utils . c_plus_c ( displacement , circle ) } }
Calculate metabolite coordinates for a new reaction metabolite.
Calculate metabolite coordinates for a new reaction metabolite .
// new local coordinate system // Curve parameters // distance between reactants and between products // bezier target poin // y distance of first secondary mets // y distance of each other secondary met // Secondary mets // Size and spacing for primary and secondary metabolites // primary // secondary // don't use center slot // distance between ends of line axis // Define line parameters and axis. // Begin with unrotated coordinate system. +y = Down, +x = Right. // Reactants // Ali == BADASS // products