updated allocationText()

This commit is contained in:
tim
2025-02-23 10:12:59 -04:00
parent 2397ebfe45
commit 956d79c3dc
6 changed files with 15 additions and 7 deletions

View File

@@ -39,7 +39,7 @@ export const ShapeType = {
}
export function allocationText(weight, amount, symbol, separator = ' ') {
export function allocationText(buy, weight, amount, symbol, separator = ' ') {
// set breakout=true for a buy breakout and breakout=false for a sell breakout
const hasAmount = amount !== null && amount !== undefined && amount > 0
if (hasAmount)
@@ -47,7 +47,9 @@ export function allocationText(weight, amount, symbol, separator = ' ') {
const hasWeight = weight !== null && weight !== undefined && weight !== 1
if (hasWeight)
weight = Number(weight)
let text = ''
if (buy===undefined)
console.error('allocation text buy', buy)
let text = buy === undefined ? '' : buy ? 'Buy ' : 'Sell '
if (hasWeight)
text += `${(weight * 100).toFixed(1)}%`
const hasSymbol = symbol !== null && symbol !== undefined
@@ -136,6 +138,8 @@ export class Shape {
this.model.breakout = model.breakout
if (defined(model.textLocation))
this.model.textLocation = model.textLocation
if (defined(model.buy))
this.model.buy = model.buy
const newProps = {}
@@ -160,7 +164,7 @@ export class Shape {
newProps.linecolor = color
// text label
let text = allocationText(this.model.allocation, this.model.amount, this.model.amountSymbol)
let text = allocationText(this.model.buy, this.model.allocation, this.model.amount, this.model.amountSymbol)
if (this.model.breakout)
text += ' ' + (this.model.textLocation==='above' ? '▲Breakout▲' : '▼Breakout▼')
if (this.model.extraText)