import React from "react"; import { getCommonBounds } from "../element/bounds"; import { mutateElement } from "../element/mutateElement"; import { ExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { KEYS } from "../keys"; import { getTargetElements } from "../scene"; import Scene from "../scene/Scene"; import { AppState, ExcalidrawProps } from "../types"; import { CloseIcon } from "./icons"; import { Island } from "./Island"; import "./Stats.scss"; interface StatsProps { appState: AppState; scene: Scene; setAppState: React.Component["setState"]; onClose: () => void; renderCustomStats: ExcalidrawProps["renderCustomStats"]; } export const Stats = (props: StatsProps) => { const elements = props.scene.getNonDeletedElements(); const boundingBox = getCommonBounds(elements); const selectedElements = getTargetElements(elements, props.appState); const selectedBoundingBox = getCommonBounds(selectedElements); const stats = selectedElements.length === 1 ? [ { label: "X", value: Math.round(selectedBoundingBox[0]), element: selectedElements[0], property: "x", }, { label: "Y", value: Math.round(selectedBoundingBox[1]), element: selectedElements[0], property: "y", }, { label: "W", value: Math.round(selectedBoundingBox[2] - selectedBoundingBox[0]), element: selectedElements[0], property: "width", }, { label: "H", value: Math.round(selectedBoundingBox[3] - selectedBoundingBox[1]), element: selectedElements[0], property: "height", }, { label: "A", value: selectedElements[0].angle, element: selectedElements[0], property: "angle", }, ] : []; return (
{CloseIcon}

{t("stats.generalStats")}

{props.renderCustomStats?.(elements, props.appState)}
{t("stats.scene")}
{t("stats.elements")} {elements.length}
{t("stats.width")} {Math.round(boundingBox[2]) - Math.round(boundingBox[0])}
{t("stats.height")} {Math.round(boundingBox[3]) - Math.round(boundingBox[1])}
{selectedElements.length > 0 && (

{t("stats.elementStats")}

{selectedElements.length === 1 && (
{t(`element.${selectedElements[0].type}`)}
)}
{stats.map((statsItem) => ( ))}
)}
); };