Skip to content
Open
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
10 changes: 10 additions & 0 deletions packages/semi-ui/progress/_story/progress.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ CircleProgressSmall.story = {
name: 'circle progress small',
};

export const DashboardProgress = () => (
<React.Fragment>
<Progress percent={20} type="dashboard" aria-label="disk usage"/>
</React.Fragment>
);

DashboardProgress.story = {
name: 'dashboard progress',
};

export const ProgressShowInfo = () => (
<div style={{ width: 200 }}>
{/* <Progress percent={10} style= {{ height: 10 }}/> */}
Expand Down
28 changes: 25 additions & 3 deletions packages/semi-ui/progress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export interface ProgressProps {
strokeLinecap?: 'round' | 'square';
strokeWidth?: number;
style?: React.CSSProperties;
type?: 'line' | 'circle';
type?: 'line' | 'circle' | 'dashboard';
gapAngle?: number;
width?: number
}

Expand Down Expand Up @@ -65,6 +66,7 @@ class Progress extends Component<ProgressProps, ProgressState> {
strokeWidth: PropTypes.number,
style: PropTypes.object,
type: PropTypes.oneOf(strings.types),
gapAngle: PropTypes.number,
width: PropTypes.number,
};

Expand All @@ -83,6 +85,7 @@ class Progress extends Component<ProgressProps, ProgressState> {
strokeWidth: 4,
style: {},
type: strings.DEFAULT_TYPE,
gapAngle: 90,
};

_mounted: boolean = true;
Expand Down Expand Up @@ -160,6 +163,8 @@ class Progress extends Component<ProgressProps, ProgressState> {
percent,
orbitStroke,
id,
type,
gapAngle,
...rest
} = this.props;
const ariaLabel = this.props['aria-label'];
Expand Down Expand Up @@ -189,8 +194,19 @@ class Progress extends Component<ProgressProps, ProgressState> {
const cx = width / 2;
const radius = (width - strokeWidth) / 2; // radius
const circumference = radius * 2 * Math.PI;
const strokeDashoffset = (1 - perc / 100) * circumference; // Offset
const strokeDasharray = `${circumference} ${circumference}`;
let strokeDashoffset = 0; // Offset
let dashLength = circumference;
let circleStyle: React.CSSProperties = {};
if (type === 'dashboard') {
const angle = gapAngle > 180 ? 180 : gapAngle;
dashLength = circumference - this.angleToArcLength(angle, circumference);
circleStyle.transformOrigin = `${cx}px ${cy}px`;
circleStyle.transform = angle > 0 ? `rotate(${90 + angle / 2}deg)` : undefined;
strokeDashoffset = (1 - perc / 100) * dashLength;
} else if (type === 'circle') {
strokeDashoffset = (1 - perc / 100) * circumference;
}
const strokeDasharray = `${dashLength} ${circumference}`;

const text = format(percNumber);

Expand All @@ -216,6 +232,7 @@ class Progress extends Component<ProgressProps, ProgressState> {
strokeLinecap={strokeLinecap}
fill="transparent"
stroke={orbitStroke}
style={circleStyle}
r={radius}
cx={cx}
cy={cy}
Expand All @@ -229,6 +246,7 @@ class Progress extends Component<ProgressProps, ProgressState> {
strokeLinecap={strokeLinecap}
fill="transparent"
stroke={_stroke}
style={circleStyle}
r={radius}
cx={cx}
cy={cy}
Expand All @@ -240,6 +258,10 @@ class Progress extends Component<ProgressProps, ProgressState> {
);
}

angleToArcLength(angle: number, circumference) {
return angle / 360 * circumference;
}

calcPercent(percent: number): number {
let perc;
if (percent > 100) {
Expand Down