import React from "react"; import { getCommonBounds } from "../element/bounds"; import { NonDeletedExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { useDeviceType } from "../components/App"; import { getTargetElements } from "../scene"; import { AppState, ExcalidrawProps } from "../types"; import { close } from "./icons"; import { Island } from "./Island"; import "./Stats.scss"; export const Stats = (props: { appState: AppState; setAppState: React.Component["setState"]; elements: readonly NonDeletedExcalidrawElement[]; onClose: () => void; renderCustomStats: ExcalidrawProps["renderCustomStats"]; }) => { const deviceType = useDeviceType(); const boundingBox = getCommonBounds(props.elements); const selectedElements = getTargetElements(props.elements, props.appState); const selectedBoundingBox = getCommonBounds(selectedElements); if (deviceType.isMobile && props.appState.openMenu) { return null; } return (
{close}

{t("stats.title")}

{selectedElements.length === 1 && ( )} {selectedElements.length > 1 && ( <> )} {selectedElements.length > 0 && ( <> )} {selectedElements.length === 1 && ( )} {props.renderCustomStats?.(props.elements, props.appState)}
{t("stats.scene")}
{t("stats.elements")} {props.elements.length}
{t("stats.width")} {Math.round(boundingBox[2]) - Math.round(boundingBox[0])}
{t("stats.height")} {Math.round(boundingBox[3]) - Math.round(boundingBox[1])}
{t("stats.element")}
{t("stats.selected")}
{t("stats.elements")} {selectedElements.length}
{"x"} {Math.round(selectedBoundingBox[0])}
{"y"} {Math.round(selectedBoundingBox[1])}
{t("stats.width")} {Math.round( selectedBoundingBox[2] - selectedBoundingBox[0], )}
{t("stats.height")} {Math.round( selectedBoundingBox[3] - selectedBoundingBox[1], )}
{t("stats.angle")} {`${Math.round( (selectedElements[0].angle * 180) / Math.PI, )}°`}
); };