From 30743ec7266aa131f72b9e1e02adab635f8a1236 Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Wed, 22 Mar 2023 18:32:21 +0800 Subject: [PATCH] split stats into general and element stats --- src/actions/types.ts | 3 +- src/components/Stats.scss | 10 +++ src/components/Stats.tsx | 129 +++++++++++++++++++++++++++++++------- src/locales/en.json | 15 ++++- 4 files changed, 131 insertions(+), 26 deletions(-) diff --git a/src/actions/types.ts b/src/actions/types.ts index e46cd2ab8..ab41c1d25 100644 --- a/src/actions/types.ts +++ b/src/actions/types.ts @@ -115,7 +115,8 @@ export type ActionName = | "toggleLinearEditor" | "toggleEraserTool" | "toggleHandTool" - | "createContainerFromText"; + | "createContainerFromText" + | "elementStats"; export type PanelComponentProps = { elements: readonly ExcalidrawElement[]; diff --git a/src/components/Stats.scss b/src/components/Stats.scss index 0a2f6b62d..a79e3e0e0 100644 --- a/src/components/Stats.scss +++ b/src/components/Stats.scss @@ -9,6 +9,10 @@ z-index: 10; pointer-events: all; + .section { + padding: 12px; + } + h3 { margin: 0 24px 8px 0; white-space: nowrap; @@ -39,6 +43,12 @@ } } + .divider { + width: 100%; + height: 1px; + background-color: var(--default-border-color); + } + :root[dir="rtl"] & { left: 12px; right: initial; diff --git a/src/components/Stats.tsx b/src/components/Stats.tsx index 7c98219bd..fd608d174 100644 --- a/src/components/Stats.tsx +++ b/src/components/Stats.tsx @@ -2,6 +2,7 @@ import React from "react"; import { getCommonBounds } from "../element/bounds"; import { NonDeletedExcalidrawElement } from "../element/types"; import { t } from "../i18n"; +import { getTargetElements } from "../scene"; import { AppState, ExcalidrawProps } from "../types"; import { CloseIcon } from "./icons"; import { Island } from "./Island"; @@ -15,34 +16,114 @@ export const Stats = (props: { renderCustomStats: ExcalidrawProps["renderCustomStats"]; }) => { const boundingBox = getCommonBounds(props.elements); + const selectedElements = getTargetElements(props.elements, props.appState); + const selectedBoundingBox = getCommonBounds(selectedElements); return (
- -
- {CloseIcon} + +
+
+ {CloseIcon} +
+

{t("stats.generalStats")}

+ + + + + + + + + + + + + + + + + + {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.title")}

- - - - - - - - - - - - - - - - - - {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])}
+ + {selectedElements.length > 0 && ( + <> +
+ +
+

{t("stats.elementStats")}

+ + + + {selectedElements.length === 1 && ( + + + + )} + + {selectedElements.length > 1 && ( + <> + + + + + + + + + )} + {selectedElements.length > 0 && ( + <> + + + + + + + + + + + + + + + + + + )} + {selectedElements.length === 1 && ( + + + + + )} + +
+ {t(`element.${selectedElements[0].type}`)} +
{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, + )}°`} +
+
+ + )}
); diff --git a/src/locales/en.json b/src/locales/en.json index 588a60b44..41050b47d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -239,6 +239,17 @@ "eraser": "Eraser", "hand": "Hand (panning tool)" }, + "element": { + "rectangle": "Rectangle", + "diamond": "Diamond", + "ellipse": "Ellipse", + "arrow": "Arrow", + "line": "Line", + "freeDraw": "Freedraw", + "text": "Text", + "image": "Image", + "group": "Group" + }, "headings": { "canvasActions": "Canvas actions", "selectedShapeActions": "Selected shape actions", @@ -400,7 +411,9 @@ "scene": "Scene", "selected": "Selected", "storage": "Storage", - "title": "General stats", + "title": "Stats", + "generalStats": "General stats", + "elementStats": "Element stats", "total": "Total", "version": "Version", "versionCopy": "Click to copy",