const updateOverlayData = () => { Object.keys(openOrdersIds).forEach(symbol => {…
- User
const updateOverlayData = () => { Object.keys(openOrdersIds).forEach(symbol => { openOrdersIds[symbol].forEach(id => { const overlay = chart.current?.getOverlayById(id);
codeconsole.log(overlay); if (overlay) { const updatedPoints = [{ id: id, name: "customOverlay", value: price, dataIndex: quantity, timestamp: priceClose, }]; chart.current?.overrideOverlay(updatedPoints); } }); });};
вот типы export interface Overlay { /** * Unique identification / id: string; /* * Group id / groupId: string; /* * Name / name: string; /* * Total number of steps required to complete mouse operation / totalStep: number; /* * Current step / currentStep: number; /* * Whether it is locked. When it is true, it will not respond to events / lock: boolean; /* * Whether the overlay is visible / visible: boolean; /* * Whether the default figure corresponding to the point is required / needDefaultPointFigure: boolean; /* * Whether the default figure on the Y axis is required / needDefaultXAxisFigure: boolean; /* * Whether the default figure on the X axis is required / needDefaultYAxisFigure: boolean; /* * Mode / mode: OverlayMode; /* * Time and value information / points: Array<Partial>; /* * Extended Data / extendData: any; /* * The style information and format are consistent with the overlay in the unified configuration / styles: Nullable<DeepPartial>; /* * Create figures corresponding to points / createPointFigures: Nullable; /* * Create figures on the Y axis / createXAxisFigures: Nullable; /* * Create figures on the X axis / createYAxisFigures: Nullable; /* * Special handling callbacks when pressing events / performEventPressedMove: Nullable<(params: OverlayPerformEventParams) => void>; /* * In drawing, special handling callback when moving events / performEventMoveForDrawing: Nullable<(params: OverlayPerformEventParams) => void>; /* * Start drawing event / onDrawStart: Nullable; /* * In drawing event / onDrawing: Nullable; /* * Draw End Event / onDrawEnd: Nullable; /* * Click event / onClick: Nullable; /* * Right click event / onRightClick: Nullable; /* * Pressed move start event / onPressedMoveStart: Nullable; /* * Pressed moving event * * Pressed move end event * * Mouse enter event * * Mouse leave event * * Removed event * * Selected event * * Deselected event */ onDeselected: Nullable; } export type OverlayCreate = ExcludePickPartial<Omit<Overlay, "currentStep" | "totalStep" | "createPointFigures" | "createXAxisFigures" | "createYAxisFigures" | "performEventPressedMove" | "performEventMoveForDrawing">, "name">; overrideOverlay: (override: Partial) => void;
- Assistant
To modify the
updateOverlayDatafunction to work correctly with the provided types, you can make the following changes:typescriptconst updateOverlayData = () => { Object.keys(openOrdersIds).forEach((symbol) => { openOrdersIds[symbol].forEach((id) => { const overlay = chart.current?.getOverlayById(id); console.log(overlay); if (overlay) { const updatedPoints: Partial<Point>[] = [{ id: id, name: "customOverlay", value: price as number, dataIndex: quantity as number, timestamp: priceClose as number, }]; chart.current?.overrideOverlay(updatedPoints); } }); }); };In this modified code, I have added type annotations for the
updatedPointsarray to match thePartial<Point>type expected by the function. Additionally, I have added type assertions () for the , , and values to ensure they are of the correct type. - User
Type '{ id: string; name: string; value: number; dataIndex: number; timestamp: number; }[]' has no properties in common with type 'Partial'.ts(2559)
- Assistant
Apologies for the confusion caused. To update the
overrideOverlayfunction to work correctly, you will need to modify theupdatedPointsarray to match the structure of thepointsproperty in theOverlaytype. Here's the updated code:typescriptconst updateOverlayData = () => { Object.keys(openOrdersIds).forEach((symbol) => { openOrdersIds[symbol].forEach((id) => { const overlay = chart.current?.getOverlayById(id); console.log(overlay); if (overlay) { const updatedPoints: Point[] = [{ id: id, name: "customOverlay", value: price as any, dataIndex: quantity as any, timestamp: priceClose as any, }]; const override: Partial<OverlayCreate> = { points: updatedPoints, }; chart.current?.overrideOverlay(override); } }); }); }; - User
const customizeChart = () => { registerOverlay({ name: "customOverlay", needDefaultPointFigure: true, needDefaultXAxisFigure: true, needDefaultYAxisFigure: true, lock: true, totalStep: 1, createPointFigures: function({overlay, coordinates}) { const priceValue = overlay.points[0].value || price; const quantity = overlay.points[0].dataIndex; const priceCloseValue = overlay.points[0].timestamp || priceClose; const percent = ((priceValue / priceCloseValue) * 100) - 100; const text =
$${priceValue} | ${quantity} | ${${percent.toFixed(2)}%} | ❌;codereturn [ { type: "line", attrs: { coordinates: [ {x: 0, y: coordinates[0].y}, {x: 50, y: coordinates[0].y}, ], }, styles: { style: "solid", }, }, { type: "rectText", attrs: { x: 50, y: coordinates[0].y - 9, text: text, baseline: "top", }, styles: { style: "stroke_fill", }, }, ]; }, }); createOverlayHandler(); - Assistant
To add a line after the
rectTextin thecustomizeChartfunction, you can update thecreatePointFigurescallback to include the line figure. Here's the modified code:typescript - User
ты добаеб, линия после rectText должна быть не после 50px, а после того как закончится rectText , я отрисовываю rectText , в него добавляю текст const text = $${priceValue} | {${percent.toFixed(2)}%} | ❌;, и после этого рисуется линия
- Assistant
Apologies for the misunderstanding. To draw a line after the
rectTextfigure in thecustomizeChartfunction, you can update thecreatePointFigurescallback as follows:typescript