split stats into general and element stats
This commit is contained in:
parent
86d49a273b
commit
30743ec726
@ -115,7 +115,8 @@ export type ActionName =
|
|||||||
| "toggleLinearEditor"
|
| "toggleLinearEditor"
|
||||||
| "toggleEraserTool"
|
| "toggleEraserTool"
|
||||||
| "toggleHandTool"
|
| "toggleHandTool"
|
||||||
| "createContainerFromText";
|
| "createContainerFromText"
|
||||||
|
| "elementStats";
|
||||||
|
|
||||||
export type PanelComponentProps = {
|
export type PanelComponentProps = {
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
z-index: 10;
|
z-index: 10;
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
|
|
||||||
|
.section {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
margin: 0 24px 8px 0;
|
margin: 0 24px 8px 0;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@ -39,6 +43,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.divider {
|
||||||
|
width: 100%;
|
||||||
|
height: 1px;
|
||||||
|
background-color: var(--default-border-color);
|
||||||
|
}
|
||||||
|
|
||||||
:root[dir="rtl"] & {
|
:root[dir="rtl"] & {
|
||||||
left: 12px;
|
left: 12px;
|
||||||
right: initial;
|
right: initial;
|
||||||
|
@ -2,6 +2,7 @@ import React from "react";
|
|||||||
import { getCommonBounds } from "../element/bounds";
|
import { getCommonBounds } from "../element/bounds";
|
||||||
import { NonDeletedExcalidrawElement } from "../element/types";
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
|
import { getTargetElements } from "../scene";
|
||||||
import { AppState, ExcalidrawProps } from "../types";
|
import { AppState, ExcalidrawProps } from "../types";
|
||||||
import { CloseIcon } from "./icons";
|
import { CloseIcon } from "./icons";
|
||||||
import { Island } from "./Island";
|
import { Island } from "./Island";
|
||||||
@ -15,34 +16,114 @@ export const Stats = (props: {
|
|||||||
renderCustomStats: ExcalidrawProps["renderCustomStats"];
|
renderCustomStats: ExcalidrawProps["renderCustomStats"];
|
||||||
}) => {
|
}) => {
|
||||||
const boundingBox = getCommonBounds(props.elements);
|
const boundingBox = getCommonBounds(props.elements);
|
||||||
|
const selectedElements = getTargetElements(props.elements, props.appState);
|
||||||
|
const selectedBoundingBox = getCommonBounds(selectedElements);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="Stats">
|
<div className="Stats">
|
||||||
<Island padding={2}>
|
<Island>
|
||||||
<div className="close" onClick={props.onClose}>
|
<div className="section">
|
||||||
{CloseIcon}
|
<div className="close" onClick={props.onClose}>
|
||||||
|
{CloseIcon}
|
||||||
|
</div>
|
||||||
|
<h3>{t("stats.generalStats")}</h3>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th colSpan={2}>{t("stats.scene")}</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.elements")}</td>
|
||||||
|
<td>{props.elements.length}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.width")}</td>
|
||||||
|
<td>
|
||||||
|
{Math.round(boundingBox[2]) - Math.round(boundingBox[0])}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.height")}</td>
|
||||||
|
<td>
|
||||||
|
{Math.round(boundingBox[3]) - Math.round(boundingBox[1])}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{props.renderCustomStats?.(props.elements, props.appState)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<h3>{t("stats.title")}</h3>
|
|
||||||
<table>
|
{selectedElements.length > 0 && (
|
||||||
<tbody>
|
<>
|
||||||
<tr>
|
<div className="divider"></div>
|
||||||
<th colSpan={2}>{t("stats.scene")}</th>
|
|
||||||
</tr>
|
<div className="section">
|
||||||
<tr>
|
<h3>{t("stats.elementStats")}</h3>
|
||||||
<td>{t("stats.elements")}</td>
|
|
||||||
<td>{props.elements.length}</td>
|
<table>
|
||||||
</tr>
|
<tbody>
|
||||||
<tr>
|
{selectedElements.length === 1 && (
|
||||||
<td>{t("stats.width")}</td>
|
<tr>
|
||||||
<td>{Math.round(boundingBox[2]) - Math.round(boundingBox[0])}</td>
|
<th colSpan={2}>
|
||||||
</tr>
|
{t(`element.${selectedElements[0].type}`)}
|
||||||
<tr>
|
</th>
|
||||||
<td>{t("stats.height")}</td>
|
</tr>
|
||||||
<td>{Math.round(boundingBox[3]) - Math.round(boundingBox[1])}</td>
|
)}
|
||||||
</tr>
|
|
||||||
{props.renderCustomStats?.(props.elements, props.appState)}
|
{selectedElements.length > 1 && (
|
||||||
</tbody>
|
<>
|
||||||
</table>
|
<tr>
|
||||||
|
<th colSpan={2}>{t("stats.selected")}</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.elements")}</td>
|
||||||
|
<td>{selectedElements.length}</td>
|
||||||
|
</tr>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{selectedElements.length > 0 && (
|
||||||
|
<>
|
||||||
|
<tr>
|
||||||
|
<td>{"x"}</td>
|
||||||
|
<td>{Math.round(selectedBoundingBox[0])}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{"y"}</td>
|
||||||
|
<td>{Math.round(selectedBoundingBox[1])}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.width")}</td>
|
||||||
|
<td>
|
||||||
|
{Math.round(
|
||||||
|
selectedBoundingBox[2] - selectedBoundingBox[0],
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.height")}</td>
|
||||||
|
<td>
|
||||||
|
{Math.round(
|
||||||
|
selectedBoundingBox[3] - selectedBoundingBox[1],
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{selectedElements.length === 1 && (
|
||||||
|
<tr>
|
||||||
|
<td>{t("stats.angle")}</td>
|
||||||
|
<td>
|
||||||
|
{`${Math.round(
|
||||||
|
(selectedElements[0].angle * 180) / Math.PI,
|
||||||
|
)}°`}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Island>
|
</Island>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -239,6 +239,17 @@
|
|||||||
"eraser": "Eraser",
|
"eraser": "Eraser",
|
||||||
"hand": "Hand (panning tool)"
|
"hand": "Hand (panning tool)"
|
||||||
},
|
},
|
||||||
|
"element": {
|
||||||
|
"rectangle": "Rectangle",
|
||||||
|
"diamond": "Diamond",
|
||||||
|
"ellipse": "Ellipse",
|
||||||
|
"arrow": "Arrow",
|
||||||
|
"line": "Line",
|
||||||
|
"freeDraw": "Freedraw",
|
||||||
|
"text": "Text",
|
||||||
|
"image": "Image",
|
||||||
|
"group": "Group"
|
||||||
|
},
|
||||||
"headings": {
|
"headings": {
|
||||||
"canvasActions": "Canvas actions",
|
"canvasActions": "Canvas actions",
|
||||||
"selectedShapeActions": "Selected shape actions",
|
"selectedShapeActions": "Selected shape actions",
|
||||||
@ -400,7 +411,9 @@
|
|||||||
"scene": "Scene",
|
"scene": "Scene",
|
||||||
"selected": "Selected",
|
"selected": "Selected",
|
||||||
"storage": "Storage",
|
"storage": "Storage",
|
||||||
"title": "General stats",
|
"title": "Stats",
|
||||||
|
"generalStats": "General stats",
|
||||||
|
"elementStats": "Element stats",
|
||||||
"total": "Total",
|
"total": "Total",
|
||||||
"version": "Version",
|
"version": "Version",
|
||||||
"versionCopy": "Click to copy",
|
"versionCopy": "Click to copy",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user