1.0.2 • Published 4 years ago

react-arc-progress v1.0.2

Weekly downloads
191
License
ISC
Repository
-
Last release
4 years ago

react-arc-progress.js

Arc animation progress bar drawn by canvas for react component 中文文档,because of the use the React Hook, dependent React version need tobe >= 16.8.0

Installation

npm install react-arc-progress -S

Usage

import ArcProgress from 'react-arc-progress';

export default class MyArcProgress extends Component {
  state = {
    progress: .782,
    text: '6439.68',
  }
  
  render() {
    const {progress, text} = this.state;
    
    return (
      <ArcProgress
        progress={progress}
        text={text}
        observer={(current) => {
          const { percentage, currentText } = current;
          console.log('observer:', percentage, currentText);
        }}
        animationEnd={({ progress, text }) => {
          console.log('animationEnd', progress, text);
        }}
      />
    );
  }
}

Props options

OptiontypeDescription
progressnumber (required)Set progress value, the range is 0 - 1
sizenumberGenerate progress bar canvas container, size by default of 200
textstringSet the text of progress bar
arcStartnumberStart point of the arc, specific usage see below
arcEndnumberEnd point of the arc, specific usage see below
thicknessnumberSet the thickness of the arc progress bar
fillThicknessnumberSet the thickness of the arc progress bar fill content,the default value is same as with thickness param when this option is not set
emptyColorstringSet the color of the empty part for the arc progress bar
fillColorstring or objectSet the style of the fill part for the arc progress bar, specific usage see below.
lineCapstringSet the style at the end of the arc progress bar, there are three optional values, namely butt, round, square. The default value is round
speednumberSet the animation speed threshold, ranging from -100 to 100, default is 0
animationboolean or numberThe duration of the animation in milliseconds. When the value is false, there is no transitional animation
textStyleobjectSet the style of text, specific usage see below
customTextarrayCustom Text Contents, specific usage see below
animationEndfunctionCallback at the end of progress bar animation
onErrorfunctionCatch the error callback
observerfunctionCallback to observer progress bar animation changes

Options Description

arcStart and arcEnd

The start point and end point of the arc are marked as show in the picture, direction is clockwise. If you want to draw a circular progress bar, you can set arcStart to 90, arcEnd to 270. Or if you want to draw a semicircle, you can set arcStart'to180', arcEnd to 360. Start and end angles can be adjusted as needed.

fillColor

fillColor is the progress bar color of the filled part, which can be passed in as its defined color(for example #ffee3c). If want used the gradient, the option need to be set to the object type, such as {gradient: [color 1, color2, color 2]}, it will be have three colors of the radial gradients. If you want use image filled, you need to set the option to the object type, the format is {image: url}, and the url is address of the picture.

textStyle

Set the style of the text content, which needs to be the object type. The optional content is as follows

NameTypeDescription
sizestringThe text size, for example 18px
colorstringThe text color, for example #fa0556
fontstringThe text font-family, for example Microsoft YaHei
xnumberX-axis of text position
ynumberY-axis of text position
customText

customText option to custom the some text contents, It is an array type. You can define more than one text. Each usage is consistent with the textStyle option, but it have one more item is text, this is used show you definition text content.

NameTypeDescription
textstringSet the text content
othersOther parameters are same as with the usage of textStyle