import {Stage } from "@pixi/react"; import {Graphics} from "@inlet/react-pixi"; export…
- User
import {Stage } from "@pixi/react"; import {Graphics} from "@inlet/react-pixi";
export interface CanvasSize { width: number; height: number; }
const OrderFeed = ({workerRef, symbol, settings}: OrderFeedProps) => { const cupParams = useSelector((state: AppState) => state.cupSlice); const [dpiScale, setDpiScale] = useState(Math.ceil(window.devicePixelRatio)); const [canvasSize, setCanvasSize] = useState({height: 0, width: 0}); const containerRef = useRef<HTMLDivElement|null>(null); const size = useComponentResizeListener(containerRef);
const [trades, setTrades] = useState<TradeItem[]>([]); const [camera, setCamera] = useState();
useEffect(() => {
workerRef.current.onmessage = (event: MessageEvent<any>) => { animationFrameId = requestAnimationFrame(() => {setTrades(event.data.trades); setCamera(event.data.camera); } ); }, [workerRef.current, canvasRef.current, canvasSize, symbol, cupParams, theme, settings.minQuantity, settings.volumeAsDollars]); useEffect(() => { if (!size) { return; } setCanvasSize({ width: Math.floor(size.width) * dpiScale, height: Math.floor(size.height) * dpiScale, }); }, [dpiScale, size]); const drawPix = useCallback((g: any) => { let startX = canvasSize.width - 10 * dpiScale; const fullHeightRowsCount = parseInt((canvasSize.height / cupParams.cellHeight).toFixed(0)); const startY = (fullHeightRowsCount % 2 ? fullHeightRowsCount - 1 : fullHeightRowsCount) / 2 * cupParams.cellHeight; const halfCupCellHeight = cupParams.cellHeight / 2; const color = orderFeedOptions(theme).line.color;
g.beginFill(color); trades?.forEach(trade => { const yModifier = (trade.price - (trade.price - (trade?.secondPrice || trade.price)) / 2 - camera) / cupParams.aggregatedPriceStep * cupParams.cellHeight + halfCupCellHeight; const width = 1.75 * clamp((trade.quantity / cupParams.quantityDivider < (!settings.minQuantity ? 0 : parseFloat(settings.minQuantity)) ? 0 : trade.radius), 5, 50) * dpiScale; g.lineStyle(4, "#006943", 1); g.lineTo(startX - width / 2, startY - yModifier); startX = startX - width; g.endFill(); });}, [trades, camera]); return ( <Box ref={containerRef} className={
${styles.canvasWrapper} scroll-block}> <Stage width={canvasSize?.width} height={canvasSize?.height} options={{backgroundColor: 0xeef1f5}}> ); };обнови код, чтобы правлиьно работала библиотеа
- Assistant
import React, { useRef, useEffect, useState, useCallback } from "react"; import { Stage, Graphics } from "@inlet/react-pixi"; import { useSelector } from "react-redux";
- User
и че ты сделал, библиотека работает некорректно
- Assistant
- User
const drawPix = useCallback((g: any) => { let startX = canvasSize.width - 10 * dpiScale; const fullHeightRowsCount = parseInt((canvasSize.height / cupParams.cellHeight).toFixed(0)); const startY = (fullHeightRowsCount % 2 ? fullHeightRowsCount - 1 : fullHeightRowsCount) / 2 * cupParams.cellHeight; const halfCupCellHeight = cupParams.cellHeight / 2; let timestamp: number|null = null;
trades.forEach(trade => { if (startX < 0) return; const isSquare = trade?.secondPrice && trade.price !== trade.secondPrice; const yModifier = (trade.price - camera) / cupParams.aggregatedPriceStep * cupParams.cellHeight + halfCupCellHeight; const prevYModifier = isSquare ? ((trade?.secondPrice || 0) - camera) / cupParams.aggregatedPriceStep * cupParams.cellHeight + halfCupCellHeight : 0; const quantity = settings.volumeAsDollars ? (trade.quantity / cupParams.quantityDivider) * (trade.price / cupParams.priceDivider) : trade.quantity / cupParams.quantityDivider; const minQuantity = !settings.minQuantity ? 0 : parseFloat(settings.minQuantity), console.log(isSquare); if (isSquare) { } else { startX = drawCircle( g, trade.price, trade.quantity / cupParams.quantityDivider < minQuantity ? 0 : trade.radius, quantity, trade.side, dpiScale, startX, startY - yModifier, theme, timestamp === trade.timestamp, ); } timestamp = trade.timestamp; }); - Assistant
Извините за ошибки в коде. Попробуйте следующую корректировку:
const drawPix = useCallback((g: any) => { let startX = canvasSize.width - 10 * dpiScale; const fullHeightRowsCount = parseInt((canvasSize.height / cupParams.cellHeight).toFixed(0)); const startY = (fullHeightRowsCount % 2 ? fullHeightRowsCount - 1 : fullHeightRowsCount) / 2 * cupParams.cellHeight; const halfCupCellHeight = cupParams.cellHeight / 2; let timestamp: number | null = null; trades.forEach(trade => { if (startX < 0) return; const isSquare = trade?.secondPrice && trade.price !== trade.secondPrice; const yModifier = (trade.price - camera) / cupParams.aggregatedPriceStep * cupParams.cellHeight + halfCupCellHeight; const prevYModifier = isSquare ? ((trade?.secondPrice || 0) - camera) / cupParams.aggregatedPriceStep * cupParams.cellHeight + halfCupCellHeight : 0; const quantity = settings.volumeAsDollars ? (trade.quantity / cupParams.quantityDivider) * (trade.price / cupParams.priceDivider) : trade.quantity / cupParams.quantityDivider; const minQuantity = !settings.minQuantity ? 0 : parseFloat(settings.minQuantity); console.log(isSquare); if (isSquare) { // Обработка для квадрата } else { startX = drawCircle( g, trade.price, trade.quantity / cupParams.quantityDivider < minQuantity ? 0 : trade.radius, quantity, trade.side, dpiScale, startX, startY - yModifier, theme, timestamp === trade.timestamp, ); } timestamp = trade.timestamp; }); }, [trades, camera, canvasSize, cupParams, settings]);
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.