Last active
November 14, 2016 11:40
-
-
Save levvsha/f48cb319878b65781cd6d8d3490627fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [0,1,2,3,4,5]; | |
var margin = {top: 10, left: 0, bottom: 10, right: 0}; | |
var height = 200; | |
var width = 500; | |
var xScale = d3.scale.linear(); | |
var yScale = d3.scale.linear(); | |
var borderRadiusX = 20; | |
var borderRadiusY = (20); | |
xScale.domain([0, data.length]).range([0, width]); | |
yScale.domain([0, d3.max(data)]).range([0, height - margin.top - margin.bottom]); | |
var o = d3.scale.ordinal().domain(data).rangeBands([50, width]); | |
o.rangeBand(); | |
o.range(); | |
o.rangeExtent(); | |
var barGroup = g.selectAll('.bars') | |
.data(data) | |
.enter() | |
.append("g"); | |
barGroup.append("path").attr("d", roundedRect(0, 0, 20, 40, 5 , true, true, false, false)) | |
const roundedRect = ( | |
xCoord, | |
yCoord, | |
width, | |
height, | |
radius, | |
needRoundingTopLeft, | |
needRoundingTopRight, | |
needRoundingBottomLeft, | |
needRoundingBottomRight | |
) => { | |
let retval; | |
retval = 'M' + (xCoord + radius) + ',' + yCoord; | |
retval += 'h' + (width - 2 * radius); | |
if (needRoundingTopRight) { | |
retval += 'a' + radius + ',' + radius + ' 0 0 1 ' + radius + ',' + radius; | |
} else { retval += 'h' + radius; retval += 'v' + radius; } | |
retval += 'v' + (height - 2 * radius); | |
if (needRoundingBottomRight) { | |
retval += 'a' + radius + ',' + radius + ' 0 0 1 ' + -radius + ',' + radius; | |
} else { retval += 'v' + radius; retval += 'h' + -radius; } | |
retval += 'h' + (2 * radius - width); | |
if (needRoundingBottomLeft) { | |
retval += 'a' + radius + ',' + radius + ' 0 0 1 ' + -radius + ',' + -radius; | |
} else { retval += 'h' + -radius; retval += 'v' + -radius; } | |
retval += 'v' + (2 * radius - height); | |
if (needRoundingTopLeft) { | |
retval += 'a' + radius + ',' + radius + ' 0 0 1 ' + radius + ',' + -radius; | |
} else { retval += 'v' + -radius; retval += 'h' + radius; } | |
retval += 'z'; | |
return retval; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment