Last active
February 10, 2019 11:27
-
-
Save storuky/5e555bc348d92a5b78a1329cc55dc604 to your computer and use it in GitHub Desktop.
transform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spread(value) { | |
return (Math.random() - 0.5) * value * 2 | |
}, | |
transformGeneratePersonObjects(){ | |
// we could do something much smarter with object layout, but let's keep it simple | |
const { x, y } = this.baseObject.position; | |
// iterate over our Shareholders array | |
this.shareholders.forEach(shareholder => { | |
const position = { | |
x: x + this.spread(500), | |
y: y + this.spread(500) | |
} | |
const { sourceName, totalShareholding, totalShareholdingPercentage } = shareholder; | |
const content = `${sourceName} holds ${totalShareholding} shares, equating to ${totalShareholdingPercentage}% of the available shares.`; | |
// this is the magic | |
const objectPromise = this.$store.dispatch('object/create', { | |
type: "AnalysisTools_PersonObject", | |
position, | |
info: { | |
title: sourceName, | |
settings: { | |
title: sourceName, | |
notesLines: [{ | |
id: this.guid(), | |
type: "Text", | |
content | |
}] | |
} | |
} | |
}) | |
objectPromise.then(createdObject => { | |
console.log('Created object: ' + createdObject.id); | |
this.$store.dispatch("connection/create", { | |
from: this.baseObject.id, | |
to: createdObject.id | |
}); | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment