Skip to content

Commit 641eec3

Browse files
authored
Merge pull request #1 from kevinjpuscan/feature/essentials
Feature/essentials merge of realease version 1.0.2
2 parents 4264532 + 95bb051 commit 641eec3

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# react-simple-gauge
22

3-
[![NPM](https://img.shields.io/npm/v/react-simple-gauge.svg)](https://www.npmjs.com/package/react-simple-gauges) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
3+
[![NPM](https://img.shields.io/npm/v/react-simple-gauges.svg)](https://www.npmjs.com/package/react-simple-gauges) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
44

55
<img src="./.github/gauge.png" alt="demo" height="100">
66

@@ -24,6 +24,14 @@ class Example extends Component {
2424
}
2525
```
2626

27+
## Options
28+
29+
| Option | type | Description | Example |
30+
|--|--|--|--|
31+
| percent | required | Percent of progress in gauge | 75 |
32+
| color | optional | Color if not define intervals of colors | #FFFFFF, red, rgba(255,243,12,.5) |
33+
| intervals | optional | Intervals values for define color, value in [min,max> | [60,75,101] |
34+
| colors | optional | Array of colors for intervals values | ['green','grba(255,255,40,.5)','#d73a49'] |
2735
## License
2836

2937
MIT © [kevinjpuscan](https://github.com/kevinjpuscan)

example/src/App.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { SimpleGauge } from 'react-simple-gauges'
55

66
const App = () => {
77
return (<div style={{margin:'10px'}}>
8-
9-
<SimpleGauge width="250px" percent="75"/>
8+
<SimpleGauge width="250px" percent="89" color="rgba(255,243,12,.5)" intervals={[60,85,101]} colors={['green','rgba(255,255,40,.8)','#d73a49']} />
109
</div>
1110
)
1211
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-simple-gauges",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A simple gauge charts for react",
55
"author": "Kevin Puscán Ortiz <[email protected]>",
66
"license": "MIT",

src/SimpleGauge/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ class SimpleGauge extends React.Component{
1010
}
1111
componentDidMount(){
1212

13-
const percent=this.props.percent?this.props.percent:100;
13+
const percent=this.props.percent?this.props.percent>=0?this.props.percent<=100?this.props.percent:100:0:100;
14+
let color=this.props.color||'#5BB030';
15+
if(this.props.intervals && this.props.colors){
16+
let startValue=0;
17+
this.props.intervals.forEach((element,idx) => {
18+
if(percent>=startValue && percent<element){
19+
color=this.props.colors[idx]||color;
20+
}
21+
startValue=element;
22+
});
23+
}
1424

1525
let container=this.container.current;
1626
const width=container.clientWidth;
@@ -51,7 +61,7 @@ class SimpleGauge extends React.Component{
5161
circle.style.strokeDashoffset=offset;
5262
circle.style.strokeWidth=strokeWidth.toString();
5363
circle.style.transform=`translate(${strokeWidth/2}px,${strokeWidth/2}px)`;
54-
64+
5565
circle=this.point.current;
5666
circle.style.width='100%';
5767
circle.style.height='100%';
@@ -66,7 +76,9 @@ class SimpleGauge extends React.Component{
6676

6777

6878
let progress=this.progress.current;
69-
progress.style.stroke='#5BB030';
79+
progress.style.stroke=color;
80+
81+
7082
progress.style.strokeDasharray=`${bar} ${offsetBar}`;
7183

7284
let point=this.point.current;
@@ -78,7 +90,7 @@ class SimpleGauge extends React.Component{
7890
text.style.fontSize=`${height/3}px`;
7991
text.style.fontWeight='bold';
8092
text.style.marginTop=`-${height/2}px`;
81-
text.style.color='#5BB030';
93+
text.style.color=color;
8294
text.style.display='grid';
8395
text.style.justifyContent='center';
8496

@@ -91,7 +103,7 @@ class SimpleGauge extends React.Component{
91103
<circle ref={this.progress}></circle>
92104
<circle ref={this.point}></circle>
93105
</svg>
94-
<div className="number" ref={this.text}>{this.props.percent?this.props.percent:100}%</div>
106+
<div className="number" ref={this.text}>{this.props.percent?this.props.percent>=0?this.props.percent<=100?this.props.percent:100:0:100}%</div>
95107
</div>
96108
);
97109
}

0 commit comments

Comments
 (0)