allocationText fix
This commit is contained in:
@@ -345,7 +345,7 @@ function doHandleCrosshairMovement(point) {
|
||||
const selection = chart.selection().allSources();
|
||||
if (selection.length)
|
||||
draggingShapeIds = selection
|
||||
console.log('dragging selected', draggingShapeIds)
|
||||
// console.log('dragging selected', draggingShapeIds)
|
||||
const initStartPoints = draggingShapeStartPoints === null
|
||||
if (initStartPoints)
|
||||
draggingShapeStartPoints = []
|
||||
|
||||
@@ -87,7 +87,7 @@ class TrancheShapes {
|
||||
price *= scale
|
||||
// console.log('price', price)
|
||||
const channel = buy?'low':'high';
|
||||
const text = allocationText(buy, weight, amount, amountSymbol, '\n', amountIsBase?null:this.symbol.base.s)
|
||||
const text = allocationText(buy, weight, amount, amountSymbol, amountIsBase ? null : this.symbol.base.s, '\n')
|
||||
const s = createShape(buy?'arrow_up':'arrow_down', {time, price}, {channel,text,lock:true})
|
||||
// console.log('created fill shape at', time, price)
|
||||
this.fills.push(s)
|
||||
|
||||
@@ -4,7 +4,7 @@ import {invokeCallback, mixin} from "@/common.js";
|
||||
import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js";
|
||||
import Color from "color";
|
||||
import {dirtyItems, dirtyPoints, nearestOhlcStart} from "@/charts/chart-misc.js";
|
||||
import {defined} from "@/misc.js";
|
||||
import {defined, toPrecision} from "@/misc.js";
|
||||
|
||||
|
||||
//
|
||||
@@ -39,8 +39,7 @@ export const ShapeType = {
|
||||
}
|
||||
|
||||
|
||||
export function allocationText(buy, weight, amount, symbol, separator = ' ', inSymbol=null) {
|
||||
// set breakout=true for a buy breakout and breakout=false for a sell breakout
|
||||
export function allocationText(buy, weight, amount, baseSymbol, amountSymbol = null, separator = ' ') {
|
||||
const hasAmount = amount !== null && amount !== undefined && amount > 0
|
||||
if (hasAmount)
|
||||
amount = Number(amount)
|
||||
@@ -52,13 +51,14 @@ export function allocationText(buy, weight, amount, symbol, separator = ' ', inS
|
||||
let text = buy === undefined ? '' : buy ? 'Buy ' : 'Sell '
|
||||
if (hasWeight)
|
||||
text += `${(weight * 100).toFixed(1)}%`
|
||||
const hasSymbol = symbol !== null && symbol !== undefined
|
||||
const hasSymbol = baseSymbol !== null && baseSymbol !== undefined
|
||||
if (hasAmount && hasSymbol) {
|
||||
if (hasWeight)
|
||||
text += separator
|
||||
if (inSymbol)
|
||||
text += `${inSymbol} worth `
|
||||
text += `${amount.toPrecision(3).toLocaleString('fullwide')} ${symbol}`
|
||||
if (amountSymbol!==null && amountSymbol!==baseSymbol)
|
||||
text += `${baseSymbol} worth ${toPrecision(amount,3)} ${amountSymbol}`
|
||||
else
|
||||
text += `${toPrecision(amount,3)} ${baseSymbol}`
|
||||
}
|
||||
return text
|
||||
}
|
||||
@@ -112,6 +112,7 @@ export class Shape {
|
||||
this.model.maxAllocation = null
|
||||
// both amount and amountSymbol must be set in order to display amount text
|
||||
this.model.amount = null
|
||||
this.model.baseSymbol = null
|
||||
this.model.amountSymbol = null
|
||||
this.model.extraText = null
|
||||
this.model.textLocation = null // defaults to 'above' if not set
|
||||
@@ -134,6 +135,8 @@ export class Shape {
|
||||
this.model.amount = model.amount
|
||||
if (defined(model.amountSymbol))
|
||||
this.model.amountSymbol = model.amountSymbol
|
||||
if (defined(model.baseSymbol))
|
||||
this.model.baseSymbol = model.baseSymbol
|
||||
if (defined(model.extraText))
|
||||
this.model.extraText = model.extraText
|
||||
if (defined(model.breakout))
|
||||
@@ -166,7 +169,7 @@ export class Shape {
|
||||
newProps.linecolor = color
|
||||
|
||||
// text label
|
||||
let text = allocationText(this.model.buy, this.model.allocation, this.model.amount, this.model.amountSymbol)
|
||||
let text = allocationText(this.model.buy, this.model.allocation, this.model.amount, this.model.baseSymbol, this.model.amountSymbol)
|
||||
if (this.model.breakout)
|
||||
text += ' ' + (this.model.textLocation==='above' ? '▲Breakout▲' : '▼Breakout▼')
|
||||
if (this.model.extraText)
|
||||
|
||||
Reference in New Issue
Block a user