if(positions[symbol]) { const position = positions[symbol]; const entryPrice =…
- User
if(positions[symbol]) {
const position = positions[symbol]; const entryPrice = position.openPrice; const formattedPrice = entryPrice.toString().replace(".", ""); console.log(entryPrice, +formattedPrice / priceDivider); // Выведет "4234" const bestPrice = formattedPrice > bestBidPrice ? bestAskPrice : bestBidPrice; const cupKeys = Object.keys(cup); const entryIndex = cupKeys.reverse().indexOf(formattedPrice.toString()); const bestPriceIndex = cupKeys.indexOf(bestPrice.toString()); const {width: textWidth} = ctx.measureText(entryPrice.toString()); // console.log(formattedPrice, bestPrice, cupKeys, entryIndex, bestPriceIndex); if(+formattedPrice <= bestBidPrice) { const height = ((entryIndex - bestPriceIndex) + 1) * cellHeight; ctx.fillStyle = "#00573761"; ctx.fillRect(size.width - cupOptions().cell.paddingX * dpiScale - textWidth - 2, (bestPriceIndex) * cellHeight, size.width, height); } else { const height = (bestPriceIndex - entryIndex) * cellHeight; ctx.fillStyle = "#b41c185c"; ctx.fillRect(size.width - cupOptions().cell.paddingX * dpiScale - textWidth - 2, entryIndex * cellHeight, size.width, height); } }нужно сделать этот квадрат поверх всех остальных
- Assistant
Для того чтобы сделать данный квадрат поверх всех остальных элементов, необходимо использовать CSS свойство "z-index". Установите значение "z-index" для квадрата, которое будет больше, чем у остальных элементов. Например:
.squared { position: absolute; z-index: 999; /* Большее значение, чем у остальных элементов */ }Затем, присвойте класс "squared" к элементу, который вы хотите поместить поверх остальных элементов:
<canvas class="squared"></canvas>Поместите этот элемент в нужное место в вашем коде, чтобы он находился поверх остальных элементов.
- User
if(formattedPrice.length !== bestBidPrice.toString().length) { formattedPrice = formattedPrice + "0"; }
нужно сделать цикл, который будет добавлять нули, пока длина прайса не будет равно бест прайсу
- Assistant
Вы можете использовать цикл
whileдля добавления нулей кformattedPrice, пока его длина не будет равна длинеbestBidPrice.toString(). Вот пример, как это можно сделать:while (formattedPrice.length !== bestBidPrice.toString().length) { formattedPrice = formattedPrice + "0"; }Этот цикл будет выполняться до тех пор, пока длина
formattedPriceне станет равной длине строки, полученной изbestBidPrice. Каждую итерацию цикла будет добавляться по одному нулю в конецformattedPrice. Когда длины будут совпадать, цикл завершится.