Dinamic numbering of parts of different types

This commit is contained in:
Luis Fernando Molina committed 2019-05-08 17:51:11 +02:00
1 parent 6b68043186
commit 99acdafdaf
2 files changed
+58 -15

No files matched your search

+43
View File
@@ -485,6 +485,7 @@ function newStrategyPart () {
const MAX_LABEL_LENGTH = 30
label = params.payload.upLabel
label = addIndexNumber(label)
if (label !== undefined) {
if (label.length > MAX_LABEL_LENGTH) {
@@ -503,6 +504,47 @@ function newStrategyPart () {
}
}
function addIndexNumber (label) {
switch (thisObject.type) {
case 'Phase': {
let parent = thisObject.payload.parentNode
for (let i = 0; i < parent.phases.length; i++) {
let phase = parent.phases[i]
if (phase.name === thisObject.payload.node.name) {
label = label + ' #' + (i + 1)
return label
}
}
break
}
case 'Situation': {
let parent = thisObject.payload.parentNode
for (let i = 0; i < parent.situations.length; i++) {
let situation = parent.situations[i]
if (situation.name === thisObject.payload.node.name) {
label = label + ' #' + (i + 1)
return label
}
}
break
}
case 'Condition': {
let parent = thisObject.payload.parentNode
for (let i = 0; i < parent.conditions.length; i++) {
let condition = parent.conditions[i]
if (condition.name === thisObject.payload.node.name) {
label = label + ' #' + (i + 1)
return label
}
}
break
}
default: {
return label
}
}
}
function drawBodyAndPicture (params) {
let position = {
x: params.container.frame.position.x,
@@ -540,3 +582,4 @@ function newStrategyPart () {
}
}
}
+15 -15
View File
@@ -80,33 +80,33 @@ function newStrategy () {
createPart('Strategy Entry Event', '', strategy.entryPoint, strategy, strategy)
for (let k = 0; k < strategy.entryPoint.situations.length; k++) {
let situation = strategy.entryPoint.situations[k]
createPart('Situation', situation.name, situation, strategy.entryPoint, strategy.entryPoint, 'Strategy Entry' + ' ' + 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, strategy.entryPoint, strategy.entryPoint, 'Strategy Entry' + ' ' + 'Situation')
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition')
}
}
createPart('Strategy Exit Event', '', strategy.exitPoint, strategy, strategy)
for (let k = 0; k < strategy.exitPoint.situations.length; k++) {
let situation = strategy.exitPoint.situations[k]
createPart('Situation', situation.name, situation, strategy.exitPoint, strategy.exitPoint, 'Strategy Exit' + ' ' + 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, strategy.exitPoint, strategy.exitPoint, 'Strategy Exit' + ' ' + 'Situation')
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition')
}
}
createPart('Trade Entry Event', '', strategy.sellPoint, strategy, strategy)
for (let k = 0; k < strategy.sellPoint.situations.length; k++) {
let situation = strategy.sellPoint.situations[k]
createPart('Situation', situation.name, situation, strategy.sellPoint, strategy.sellPoint, 'Trade Entry' + ' ' + 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, strategy.sellPoint, strategy.sellPoint, 'Trade Entry' + ' ' + 'Situation')
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition')
}
}
@@ -121,15 +121,15 @@ function newStrategy () {
chainParent = lastPhase
}
lastPhase = phase
createPart('Phase', phase.name, phase, strategy.stopLoss, chainParent, 'Stop Phase' + ' #' + (p + 1))
createPart('Phase', phase.name, phase, strategy.stopLoss, chainParent, 'Stop Phase')
for (let k = 0; k < phase.situations.length; k++) {
let situation = phase.situations[k]
createPart('Situation', situation.name, situation, phase, phase, 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, phase, phase, 'Situation')
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition')
}
}
}
@@ -144,15 +144,15 @@ function newStrategy () {
chainParent = lastPhase
}
lastPhase = phase
createPart('Phase', phase.name, phase, strategy.buyOrder, chainParent, 'Take Profit Phase' + ' #' + (p + 1))
createPart('Phase', phase.name, phase, strategy.buyOrder, chainParent, 'Take Profit Phase')
for (let k = 0; k < phase.situations.length; k++) {
let situation = phase.situations[k]
createPart('Situation', situation.name, situation, phase, phase, 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, phase, phase, 'Situation')
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition')
}
}
}
@@ -256,7 +256,7 @@ function newStrategy () {
} else {
phaseChainParent = phaseParent
}
createPart('Phase', phase.name, phase, phaseParent, phaseChainParent, 'Phase' + ' #' + (m + 1))
createPart('Phase', phase.name, phase, phaseParent, phaseChainParent, 'Phase')
}
break
case 'Add Situation':
@@ -268,7 +268,7 @@ function newStrategy () {
conditions: []
}
phase.situations.push(situation)
createPart('Situation', situation.name, situation, phase, phase, 'Situation' + ' #' + (m + 1))
createPart('Situation', situation.name, situation, phase, phase, 'Situation')
}
break
case 'Add Condition':
@@ -280,7 +280,7 @@ function newStrategy () {
code: ''
}
situation.conditions.push(condition)
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition')
}
break
case 'Delete Phase': {