Skip to content

Commit 8a450a4

Browse files
committed
Applied PR feedback for Gauge component
1 parent bb22e2b commit 8a450a4

16 files changed

Lines changed: 54 additions & 51 deletions

File tree

File renamed without changes.

src/common/components/mock-components/front-rich-components/progressIndicator/progressIndicator.tsx renamed to src/common/components/mock-components/front-rich-components/gauge/gauge.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
33
import { forwardRef } from 'react';
44
import { ShapeProps } from '../../shape.model';
55
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
6-
import { getProgressIndicatorPartsText } from './progressIndicator.utils';
76
import { useShapeProps } from '../../../shapes/use-shape-props.hook';
87

98
import { BASIC_SHAPE } from '@/common/components/mock-components/front-components/shape.const';
109
import { useGroupShapeProps } from '../../mock-components.utils';
10+
import { getGaugePartsText } from './gauge.utils';
1111

12-
const progressIndicatorShapeSizeRestrictions: ShapeSizeRestrictions = {
12+
const gaugeShapeSizeRestrictions: ShapeSizeRestrictions = {
1313
minWidth: 70,
1414
minHeight: 70,
1515
maxWidth: -1,
@@ -18,12 +18,12 @@ const progressIndicatorShapeSizeRestrictions: ShapeSizeRestrictions = {
1818
defaultHeight: 150,
1919
};
2020

21-
export const getProgressIndicatorShapeSizeRestrictions =
22-
(): ShapeSizeRestrictions => progressIndicatorShapeSizeRestrictions;
21+
export const getGaugeShapeSizeRestrictions = (): ShapeSizeRestrictions =>
22+
gaugeShapeSizeRestrictions;
2323

24-
const shapeType: ShapeType = 'progressIndicator';
24+
const shapeType: ShapeType = 'gauge';
2525

26-
export const ProgressIndicator = forwardRef<any, ShapeProps>((props, ref) => {
26+
export const Gauge = forwardRef<any, ShapeProps>((props, ref) => {
2727
const {
2828
x,
2929
y,
@@ -36,13 +36,13 @@ export const ProgressIndicator = forwardRef<any, ShapeProps>((props, ref) => {
3636
...shapeProps
3737
} = props;
3838
const restrictedSize = fitSizeToShapeSizeRestrictions(
39-
progressIndicatorShapeSizeRestrictions,
39+
gaugeShapeSizeRestrictions,
4040
width,
4141
height
4242
);
4343

4444
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
45-
const { progressIndicatorTitle } = getProgressIndicatorPartsText(text);
45+
const { gaugeValue } = getGaugePartsText(text);
4646
const { fontSize } = useShapeProps(otherProps, BASIC_SHAPE);
4747
const commonGroupProps = useGroupShapeProps(
4848
props,
@@ -52,13 +52,19 @@ export const ProgressIndicator = forwardRef<any, ShapeProps>((props, ref) => {
5252
);
5353
const { stroke, fill, textColor } = useShapeProps(otherProps, BASIC_SHAPE);
5454

55-
const progress = Number(progressIndicatorTitle || '83');
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('%');
60+
5661
const size = Math.min(restrictedWidth, restrictedHeight);
5762
const strokeWidth = Math.min(restrictedWidth, restrictedHeight) / 10;
5863
const radius = (size - strokeWidth) / 2;
5964
const center = size / 2;
6065
const angle = (progress / 100.01) * 360;
6166
const fontSizeScaled = fontSize * (size / 80);
67+
console.log(radius, center, angle, fontSizeScaled);
6268
const arcPath = () => {
6369
const startAngle = -90;
6470
const endAngle = startAngle + angle;
@@ -86,14 +92,15 @@ export const ProgressIndicator = forwardRef<any, ShapeProps>((props, ref) => {
8692

8793
{/* Percent */}
8894
<Text
89-
x={center - radius / 2}
95+
x={center - 10 - radius / 2}
9096
y={center - fontSizeScaled / 2}
91-
text={(progressIndicatorTitle || '83') + '%'}
97+
width={center + 10}
98+
text={(parsedValue || '10%') + (showPercentage ? '%' : '')}
9299
fontFamily="Arial, sans-serif"
93100
fontSize={fontSizeScaled}
101+
align="center"
94102
fill={textColor}
95103
fontStyle="bold"
96-
align="center"
97104
letterSpacing={1}
98105
wrap="none"
99106
ellipsis={true}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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() : '';
6+
7+
return { gaugeValue };
8+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './gauge';

src/common/components/mock-components/front-rich-components/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export * from './appBar';
1414
export * from './buttonBar/buttonBar';
1515
export * from './tabsbar';
1616
export * from './audio-player';
17-
export * from './progressIndicator/progressIndicator';
18-
1917
export * from './videoconference';
2018
export * from './togglelightdark-shape';
19+
export * from './gauge/gauge';

src/common/components/mock-components/front-rich-components/progressIndicator/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/common/components/mock-components/front-rich-components/progressIndicator/progressIndicator.utils.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/core/model/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ export type ShapeType =
7070
| 'tooltip'
7171
| 'slider'
7272
| 'link'
73-
| 'progressIndicator'
7473
| 'cilinder'
7574
| 'videoconference'
76-
| 'richtext';
77-
75+
| 'richtext'
76+
| 'gauge';
7877

7978
export const ShapeDisplayName: Record<ShapeType, string> = {
8079
multiple: 'multiple',
@@ -135,9 +134,9 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
135134
tooltip: 'Tooltip',
136135
slider: 'Slider',
137136
richtext: 'Rich Text',
138-
progressIndicator: 'ProgressIndicator',
139137
cilinder: 'Cilinder',
140138
videoconference: 'Videoconference',
139+
gauge: 'Gauge',
141140
};
142141

143142
export type EditType = 'input' | 'textarea' | 'imageupload';

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const inlineEditableShapes = new Set<ShapeType>([
3636
'datepickerinput',
3737
'browser',
3838
'modalDialog',
39-
'progressIndicator',
39+
'gauge',
4040
]);
4141

4242
// Check if a shape type allows inline editing
@@ -107,7 +107,7 @@ const defaultTextValueMap: Partial<Record<ShapeType, string>> = {
107107
modal:
108108
'Alert\nWarning: The action you are about to perform may affect existing data. Are you sure you want to proceed? Once confirmed, this action cannot be undone.\nConfirm,Cancel',
109109
appBar: 'AppBar',
110-
progressIndicator: '83%',
110+
gauge: '10%',
111111
buttonBar: 'Button 1, Button 2, Button 3',
112112
tabsBar: 'Tab 1, Tab 2, Tab 3',
113113
link: 'Link',
@@ -141,7 +141,7 @@ export const getShapeEditInlineType = (
141141
case 'vertical-menu':
142142
case 'table':
143143
case 'modal':
144-
case 'progressIndicator':
144+
case 'gauge':
145145
case 'appBar':
146146
case 'tabsBar':
147147
case 'tooltip':

src/pods/canvas/model/shape-other-props.utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ export const generateDefaultOtherProps = (
6767
disabled: BASIC_SHAPE.DEFAULT_DISABLED,
6868
};
6969
case 'modal':
70-
case 'progressIndicator':
70+
case 'gauge':
7171
return {
7272
backgroundColor: '#d3d3d3',
7373
stroke: '#808080',
7474
textColor: BASIC_SHAPE.DEFAULT_FILL_TEXT,
75-
strokeStyle: [],
7675
};
7776
case 'buttonBar':
7877
return {

0 commit comments

Comments
 (0)