Skip to content

Commit

Permalink
Merge pull request #10 from ricardodorosario/outline-improvement
Browse files Browse the repository at this point in the history
New properties to outline the bars
  • Loading branch information
ricardodorosario authored Mar 31, 2020
2 parents 39e2690 + 172e181 commit 35e4172
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Complete
showTextIn
showTextUp
showTextDown
outlineWidth: {0.5},
outlineColor: "black"
id="new_id"
fontColor="rgb(50,20,100)"
data={[
Expand Down Expand Up @@ -73,6 +75,8 @@ Complete
- showValueDown: PropTypes.bool
- fontColor: PropTypes.string
- onClick: PropTypes.func
- outlineWidth: PropTypes.number
- outlineColor: PropTypes.string

### Default Properties

Expand All @@ -85,6 +89,8 @@ Complete
- showValueUp: false
- showValueDown: false
- fontColor: "white"
- outlineWidth: 0
- outlineColor: "black"
- id: "hsbar"

### Data object list
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-horizontal-stacked-bar-chart",
"version": "8.14.1",
"version": "8.15.1",
"description": "React horizontal stacked bar responsive chart component",
"keywords": [
"stacked-chart",
Expand Down
30 changes: 24 additions & 6 deletions src/horizontalBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ export default class HorizontalBar extends Component {
*/
getListBarWithOtherParameters() {
const widthTotal = this.calcWidthTotal();
let position = 0;
let position = (this.props.outlineWidth * 2) / 100;
let barWidth = 0;
const listBars = this.props.data.map(bar => {
position = position + barWidth;
barWidth = (bar.value * 100) / widthTotal;
bar = Object.assign({ position: position, barWidth: barWidth }, bar);
barWidth =
(bar.value * 100) / widthTotal -
(this.props.outlineWidth * 100) / bar.value / 100;
bar = Object.assign(
{ position: position, barWidth: barWidth, widthTotal: widthTotal },
bar
);
return bar;
});
return listBars;
Expand Down Expand Up @@ -118,14 +123,23 @@ export default class HorizontalBar extends Component {
width={`${bar.barWidth + 0.1}%`}
height={this.props.height}
style={{
fill: bar.color || this.randomColor()
fill: bar.color || this.randomColor(),
strokeWidth: `${(this.props.outlineWidth * 100) /
(bar.widthTotal / this.props.data.length)}%`,
stroke: this.props.outlineColor
}}
x={`${bar.position}%`}
/>
{(this.props.showTextIn || this.props.showValueIn) && (
<text
style={{ fill: this.props.fontColor, fontSize: "90%" }}
x={`${bar.position + 1}%`}
x={
this.props.outlineWidth > 0
? `${bar.position +
(this.props.outlineWidth * 100) /
(bar.widthTotal / this.props.data.length)}%`
: `${bar.position + 1}%`
}
y="50%"
dy="0.35em"
>
Expand Down Expand Up @@ -187,7 +201,9 @@ HorizontalBar.propTypes = {
showValueUp: PropTypes.bool,
showValueDown: PropTypes.bool,
fontColor: PropTypes.string,
onClick: PropTypes.func
onClick: PropTypes.func,
outlineWidth: PropTypes.number,
outlineColor: PropTypes.string
};

HorizontalBar.defaultProps = {
Expand All @@ -199,6 +215,8 @@ HorizontalBar.defaultProps = {
showValueIn: false,
showValueUp: false,
showValueDown: false,
outlineWidth: 0,
outlineColor: "black",
fontColor: "white",
id: "hsbar"
};
4 changes: 2 additions & 2 deletions umd/hsbar.min.js

Large diffs are not rendered by default.

0 comments on commit 35e4172

Please sign in to comment.