Commit a4aac3c7 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Enable y directed regions - #132

parent 560a519e
...@@ -382,7 +382,7 @@ ...@@ -382,7 +382,7 @@
// for main // for main
margin = { margin = {
top: __axis_rotated ? getHorizontalAxisHeight('y2') : rotated_padding_top, top: __axis_rotated ? getHorizontalAxisHeight('y2') : 0,
right: getCurrentPaddingRight(), right: getCurrentPaddingRight(),
bottom: getHorizontalAxisHeight(__axis_rotated ? 'y' : 'x') + (__axis_rotated ? 0 : __subchart_size_height) + (isLegendRight ? 0 : legendHeight), bottom: getHorizontalAxisHeight(__axis_rotated ? 'y' : 'x') + (__axis_rotated ? 0 : __subchart_size_height) + (isLegendRight ? 0 : legendHeight),
left: (__axis_rotated ? __subchart_size_height + rotated_padding_right : 0) + getCurrentPaddingLeft() left: (__axis_rotated ? __subchart_size_height + rotated_padding_right : 0) + getCurrentPaddingLeft()
...@@ -1274,15 +1274,41 @@ ...@@ -1274,15 +1274,41 @@
//-- Regions --// //-- Regions --//
function regionStart(d) { function regionX(d) {
return ('start' in d) ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0; var xPos, yScale = d.axis === 'y' ? y : y2;
if (d.axis === 'y' || d.axis === 'y2') {
xPos = __axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0;
} else {
xPos = __axis_rotated ? 0 : ('start' in d ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0);
}
return xPos;
}
function regionY(d) {
var yPos, yScale = d.axis === 'y' ? y : y2;
if (d.axis === 'y' || d.axis === 'y2') {
yPos = __axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0);
} else {
yPos = __axis_rotated ? ('start' in d ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0) : 0;
}
return yPos;
} }
function regionWidth(d) { function regionWidth(d) {
var start = regionStart(d), var start = regionX(d), end, yScale = d.axis === 'y' ? y : y2;
end = ('end' in d) ? x(isTimeSeries ? parseDate(d.end) : d.end) : width, if (d.axis === 'y' || d.axis === 'y2') {
w = end - start; end = __axis_rotated ? ('end' in d ? yScale(d.end) : width) : width;
return (w < 0) ? 0 : w; } else {
end = __axis_rotated ? width : ('end' in d ? x(isTimeSeries ? parseDate(d.end) : d.end) : width);
}
return end < start ? 0 : end - start;
}
function regionHeight(d) {
var start = regionY(d), end, yScale = d.axis === 'y' ? y : y2;
if (d.axis === 'y' || d.axis === 'y2') {
end = __axis_rotated ? height : ('start' in d ? yScale(d.start) : height);
} else {
end = __axis_rotated ? ('end' in d ? x(isTimeSeries ? parseDate(d.end) : d.end) : height) : height;
}
return end < start ? 0 : end - start;
} }
//-- Data --// //-- Data --//
...@@ -3409,10 +3435,10 @@ ...@@ -3409,10 +3435,10 @@
.style("fill-opacity", 0); .style("fill-opacity", 0);
mainRegion mainRegion
.attr('class', classRegion) .attr('class', classRegion)
.attr("x", __axis_rotated ? 0 : regionStart) .attr("x", regionX)
.attr("y", __axis_rotated ? regionStart : margin.top) .attr("y", regionY)
.attr("width", __axis_rotated ? width : regionWidth) .attr("width", regionWidth)
.attr("height", __axis_rotated ? regionWidth : height) .attr("height", regionHeight)
.transition().duration(duration) .transition().duration(duration)
.style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; }); .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; });
mainRegion.exit().transition().duration(duration) mainRegion.exit().transition().duration(duration)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -11,13 +11,37 @@ ...@@ -11,13 +11,37 @@
var chart = c3.generate({ var chart = c3.generate({
data: { data: {
columns: [ columns: [
['sample', 30, 200, 100, 400, 150, 250] ['sample', 30, 200, 100, 400, 150, 250, 300]
] ]
}, },
axis: {
rotated: true,
y2: {
// show: true,
}
},
regions: [ regions: [
{start:2,end:4,class:'region1'} {end:1,class:'region1'},
{start:2,end:4,class:'region1'},
{start:5,class:'region1'},
{end:50,axis:'y'},
{start:100,end:200,axis:'y'},
{start:300,axis:'y'},
],
zoom: {
// enabled: true
}
});
/*
setTimeout(function () {
chart.load({
columns: [
['sample', -100, 200, 50, 100, 400, 299]
] ]
}); });
}, 1000);
*/
</script> </script>
</body> </body>
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment