Skip to content

Commit 368b92d

Browse files
committed
Improved gauge component
1 parent 7e946c5 commit 368b92d

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/common/components/mock-components/front-rich-components/gauge/gauge.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { useShapeProps } from '../../../shapes/use-shape-props.hook';
77

88
import { BASIC_SHAPE } from '@/common/components/mock-components/front-components/shape.const';
99
import { useGroupShapeProps } from '../../mock-components.utils';
10-
import { getGaugePartsText } from './gauge.utils';
10+
import {
11+
endsWhithPercentageSymbol,
12+
extractNumbersAsTwoDigitString,
13+
} from './gauge.utils';
1114

1215
const gaugeShapeSizeRestrictions: ShapeSizeRestrictions = {
1316
minWidth: 70,
@@ -42,7 +45,6 @@ export const Gauge = forwardRef<any, ShapeProps>((props, ref) => {
4245
);
4346

4447
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
45-
const { gaugeValue } = getGaugePartsText(text);
4648
const { fontSize } = useShapeProps(otherProps, BASIC_SHAPE);
4749
const commonGroupProps = useGroupShapeProps(
4850
props,
@@ -52,19 +54,19 @@ export const Gauge = forwardRef<any, ShapeProps>((props, ref) => {
5254
);
5355
const { stroke, fill, textColor } = useShapeProps(otherProps, BASIC_SHAPE);
5456

55-
const parsedValue = gaugeValue?.trim().endsWith('%')
56-
? gaugeValue.slice(0, -1)
57-
: gaugeValue;
58-
const progress = Number(parsedValue) || 10;
59-
const showPercentage = gaugeValue?.trim().endsWith('%');
57+
const numericPart = extractNumbersAsTwoDigitString(text);
58+
59+
const progress = Number(numericPart);
60+
const displayValue = endsWhithPercentageSymbol(text)
61+
? `${numericPart}%`
62+
: numericPart;
6063

6164
const size = Math.min(restrictedWidth, restrictedHeight);
6265
const strokeWidth = Math.min(restrictedWidth, restrictedHeight) / 10;
6366
const radius = (size - strokeWidth) / 2;
6467
const center = size / 2;
6568
const angle = (progress / 100.01) * 360;
6669
const fontSizeScaled = fontSize * (size / 80);
67-
console.log(radius, center, angle, fontSizeScaled);
6870
const arcPath = () => {
6971
const startAngle = -90;
7072
const endAngle = startAngle + angle;
@@ -95,15 +97,12 @@ export const Gauge = forwardRef<any, ShapeProps>((props, ref) => {
9597
x={center - 10 - radius / 2}
9698
y={center - fontSizeScaled / 2}
9799
width={center + 10}
98-
text={(parsedValue || '10%') + (showPercentage ? '%' : '')}
100+
text={displayValue}
99101
fontFamily="Arial, sans-serif"
100102
fontSize={fontSizeScaled}
101103
align="center"
102104
fill={textColor}
103105
fontStyle="bold"
104-
letterSpacing={1}
105-
wrap="none"
106-
ellipsis={true}
107106
/>
108107
</Group>
109108
);
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
interface GaugePartsText {
2-
gaugeValue: string;
3-
}
4-
export const getGaugePartsText = (text: string): GaugePartsText => {
5-
let gaugeValue = text ? text.replace(/\r?\n|\r/g, '').trim() : '';
1+
export const extractNumbersAsTwoDigitString = (text: string): string => {
2+
const numbersAsString = text.replace(/\D/g, '');
3+
return numbersAsString === '100' ? '100' : numbersAsString.slice(0, 2) || '0';
4+
};
65

7-
return { gaugeValue };
6+
export const endsWhithPercentageSymbol = (text: string): boolean => {
7+
return text.trim().endsWith('%');
88
};

src/pods/canvas/model/inline-editable.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const shapeTypesWithDefaultText = new Set<ShapeType>([
7979
'browser',
8080
'modalDialog',
8181
'loading-indicator',
82+
'gauge',
8283
]);
8384

8485
// Map of ShapeTypes to their default text values
@@ -144,7 +145,6 @@ export const getShapeEditInlineType = (
144145
case 'vertical-menu':
145146
case 'table':
146147
case 'modal':
147-
case 'gauge':
148148
case 'appBar':
149149
case 'tabsBar':
150150
case 'tooltip':

0 commit comments

Comments
 (0)