Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: graphics info card precision issue #202

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/core/src/graphics/graphics/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,13 @@
this.setWorldTransform(newWoldTf);
}

getInfoPanelAttrs() {
getInfoPanelAttrs(): {
label: string;
key: string;
value: number;
uiType: string;
suffixValue?: string;
}[] {
const size = this.getTransformedSize();
const pos = this.getWorldPosition();
return [
Expand Down Expand Up @@ -799,7 +805,7 @@
return content;
}

protected getSVGTagHead(_offset?: IPoint) {

Check warning on line 808 in packages/core/src/graphics/graphics/graphics.ts

View workflow job for this annotation

GitHub Actions / eslint

'_offset' is defined but never used
return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 因为运算中会丢失精度
* 如果两个数距离非常非常小,我们认为它相等
*/
const isEqual = (a: number | string, b: number) => {

Check warning on line 18 in packages/suika/src/components/Cards/ElementsInfoCard/ElementsInfoCard.tsx

View workflow job for this annotation

GitHub Actions / eslint

'isEqual' is assigned a value but never used
if (typeof a === 'string') return false;
return Math.abs(a - b) < 0.00000001;
};
Expand All @@ -25,6 +25,7 @@
key: string;
value: number | string;
uiType: string;
precision?: number;
}

export const ElementsInfoCards: FC = () => {
Expand All @@ -42,6 +43,10 @@
for (const el of items) {
const attrs = el.getInfoPanelAttrs();
for (const attr of attrs) {
if (attr.uiType === 'number') {
const precision = 2;
attr.value = remainDecimal(attr.value, precision);
}
const label = attr.label;
if (!map.has(label)) {
map.set(label, attr);
Expand Down
Loading