export interface CupHistoryItem { quantity: number; sum: number; tcks: number[]; }…
- User
export interface CupHistoryItem { quantity: number; sum: number; tcks: number[]; }
export interface CupHistory { ask: {[key: number]: CupHistoryItem}; bid: {[key: number]: CupHistoryItem}; }
let history: CupHistory = { ask: {}, bid: {}, };
let volumeAsDollars = false; let quantityDivider = 1;
const publish = () => {
const rowsHistory: CupHistory = { ask: {}, bid: {}, };postMessage({ type: "update_cup", cup: rows, history: rowsHistory, volumeAsDollars, }); };
нужно в функции publish, если volumeAsDollars true, то quantity в history в ask и bid перемножать с sum и потом делать на quantityDivider для округления, добавлять такой новй объект в rowsHistory, потом мы передаем его в postMessage
- Assistant
function publish() { const rowsHistory: CupHistory = { ask: {}, bid: {}, };
for (let key in history.ask) { const item = history.ask[key]; const updatedItem: CupHistoryItem = { quantity: volumeAsDollars ? Math.round(item.quantity * item.sum / quantityDivider) : item.quantity, sum: item.sum, tcks: item.tcks, }; rowsHistory.ask[key] = updatedItem; }
for (let key in history.bid) { const item = history.bid[key]; const updatedItem: CupHistoryItem = { quantity: volumeAsDollars ? Math.round(item.quantity * item.sum / quantityDivider) : item.quantity, sum: item.sum, tcks: item.tcks, }; rowsHistory.bid[key] = updatedItem; }
postMessage({ type: "update_cup", cup: rows, history: rowsHistory, volumeAsDollars, }); }
- User
export interface CupHistoryItem { quantity: number; sum: number; tcks: number[]; }
cupDrawer.drawHistoryQuantity( ctx, historyItem, side, isBestPrice, yPosition, cellHeight, fullWidthAsMarginForOrders, dpiScale, darkMode );
drawHistoryBidQuantity: ( ctx: CanvasRenderingContext2D, quantity: number, side: string, isBestPrice: boolean, yPosition: number, cellHeight: number, fullWidth: number, dpiScale: number, darkMode: boolean, ) => { ctx.textBaseline = "middle"; const {width} = ctx.measureText(
${quantity / 10}); const textWidth = width + cupOptions().cell.paddingX * dpiScale * 2; ctx.fillStyle = "#cad7cd" ctx.fillRect(marginForOrders + 100, yPosition + 3, textWidth + 2, 26);code// ctx.fillStyle = "#212121" ctx.fillStyle = cupTools.getQuantityColor(side, isBestPrice, darkMode); ctx.fillText( `${quantity / 10}`, marginForOrders + 100 + cupOptions().cell.paddingX * dpiScale, yPosition + cellHeight / 2, );},
нужно изменить отрисовку, отрисовывать не quantity, а отрисовывать массив tcks, мы обрезаем tcks.slice(0, 10), и отрисовываем каждый tck, x мы берем marginForOrders + 100 и плюс ширина + 4 px, чтобы у нас было по порядку отрисованы tck
- Assistant
function drawHistoryBidQuantity( ctx: CanvasRenderingContext2D, tcks: number[], side: string, isBestPrice: boolean, yPosition: number, cellHeight: number, fullWidth: number, dpiScale: number, darkMode: boolean ) { ctx.textBaseline = "middle"; const marginForOrders = fullWidth * cupOptions().fullWidthAsMargin; const paddingX = cupOptions().cell.paddingX * dpiScale; const textHeight = cupOptions().cell.fontSize * dpiScale; const textWidth = paddingX * 2 + textHeight; // square box for each tck
ctx.fillStyle = "#cad7cd"; ctx.fillRect(marginForOrders + 100, yPosition + 3, textWidth * tcks.slice(0, 10).length + 4, 26);
const quantityColor = cupTools.getQuantityColor(side, isBestPrice, darkMode); ctx.fillStyle = quantityColor;
tcks.slice(0, 10).forEach((tck, index) => { const xPosition = marginForOrders + 100 + (textWidth * index) + paddingX; ctx.fillText(
${tck}, xPosition, yPosition + cellHeight / 2); }); } - User
если тик равен 0, то отрисовывать не нужно
- Assistant
function drawHistoryBidQuantity( ctx: CanvasRenderingContext2D, tcks: number[], side: string, isBestPrice: boolean, yPosition: number, cellHeight: number, fullWidth: number, dpiScale: number, darkMode: boolean ) { ctx.textBaseline = "middle"; const marginForOrders = fullWidth * cupOptions().fullWidthAsMargin; const paddingX = cupOptions().cell.paddingX * dpiScale; const textHeight = cupOptions().cell.fontSize * dpiScale; const textWidth = paddingX * 2 + textHeight; // square box for each tck
ctx.fillStyle = "#cad7cd"; ctx.fillRect(marginForOrders + 100, yPosition + 3, textWidth * tcks.slice(0, 10).length + 4, 26);
const quantityColor = cupTools.getQuantityColor(side, isBestPrice, darkMode); ctx.fillStyle = quantityColor;
tcks.slice(0, 10).forEach((tck, index) => { if (tck !== 0) { const xPosition = marginForOrders + 100 + (textWidth * index) + paddingX; ctx.fillText(
${tck}, xPosition, yPosition + cellHeight / 2); } }); }