Commit c4ee971a authored by Masayuki Tanaka's avatar Masayuki Tanaka Committed by masayuki

Fix ygrid

parent d05252ef
...@@ -562,7 +562,7 @@ ...@@ -562,7 +562,7 @@
function init (data) { function init (data) {
var targets = c3.data.targets = convertDataToTargets(data) var targets = c3.data.targets = convertDataToTargets(data)
var rectWidth var rectWidth
var grid, xgridLine, yGridData var grid, xgridLine
// TODO: set names if names not specified // TODO: set names if names not specified
...@@ -614,11 +614,10 @@ ...@@ -614,11 +614,10 @@
// Y-Grid // Y-Grid
if (__grid_y_show) { if (__grid_y_show) {
yGridData = y.ticks(10)
grid.append('g') grid.append('g')
.attr('class', 'ygrid') .attr('class', 'ygrids')
.selectAll("line.ygrid") .selectAll(".ygrid")
.data(yGridData) .data(y.ticks(10))
.enter().append("line") .enter().append("line")
.attr("class", "ygrid") .attr("class", "ygrid")
.attr("x1", 0) .attr("x1", 0)
...@@ -629,10 +628,10 @@ ...@@ -629,10 +628,10 @@
if (__grid_y_lines) { if (__grid_y_lines) {
grid.append('g') grid.append('g')
.attr('class', 'ygrid-lines') .attr('class', 'ygrid-lines')
.selectAll('line.y') .selectAll('ygrid-line')
.data(__grid_y_lines) .data(__grid_y_lines)
.enter().append('line') .enter().append('line')
.attr("class", function(d){ return "y " + d['class'] }) .attr("class", function(d){ return "ygrid-line " + d['class'] })
.attr("x1", 0) .attr("x1", 0)
.attr("x2", width) .attr("x2", width)
.attr("y1", function(d){ return y(d.value) }) .attr("y1", function(d){ return y(d.value) })
...@@ -912,7 +911,7 @@ ...@@ -912,7 +911,7 @@
draw(targets) draw(targets)
} }
function update (withTransition) { function update (withTransition, withY) {
var xgrid, xgridData, xgridLine var xgrid, xgridData, xgridLine
var mainPath, mainCircle, mainBar, contextPath var mainPath, mainCircle, mainBar, contextPath
var barTargetsNum = getTargetsNum(isBarType), barIndices = getBarTargetIndices() var barTargetsNum = getTargetsNum(isBarType), barIndices = getBarTargetIndices()
...@@ -940,13 +939,9 @@ ...@@ -940,13 +939,9 @@
xgrid = main.select('g.xgrid').selectAll("line.xgrid") xgrid = main.select('g.xgrid').selectAll("line.xgrid")
.data(xgridData) .data(xgridData)
// Enter
xgrid.enter().append('line').attr("class", "xgrid") xgrid.enter().append('line').attr("class", "xgrid")
// Exit
xgrid.exit().remove() xgrid.exit().remove()
// Update
main.selectAll("line.xgrid") main.selectAll("line.xgrid")
.attr("class", "xgrid")
.attr("x1", x) .attr("x1", x)
.attr("x2", x) .attr("x2", x)
.attr("y1", margin.top) .attr("y1", margin.top)
...@@ -960,6 +955,26 @@ ...@@ -960,6 +955,26 @@
xgridLine.selectAll('text') xgridLine.selectAll('text')
.attr("x", function(d){ return x(d.value) }) .attr("x", function(d){ return x(d.value) })
} }
// Y-Grid
if (__grid_y_show && withY) {
ygrid = main.select('.ygrids').selectAll(".ygrid")
.data(y.ticks(10))
ygrid.enter().append('line')
.attr('class', 'ygrid')
ygrid.attr("x1", 0)
.attr("x2", width)
.attr("y1", y)
.attr("y2", y)
.attr("opacity", 0)
.transition()
.attr("opacity", 1)
ygrid.exit().remove()
}
if (__grid_y_lines && withY) {
main.select('.ygrid-lines').selectAll('.ygrid-line')
.attr("y1", function(d){ return y(d.value) })
.attr("y2", function(d){ return y(d.value) })
}
// lines and cricles // lines and cricles
mainPath = main.selectAll('.target').selectAll('.target-line').filter(isLineType) mainPath = main.selectAll('.target').selectAll('.target-line').filter(isLineType)
...@@ -1186,6 +1201,8 @@ ...@@ -1186,6 +1201,8 @@
main.select('.y.axis').transition().call(yAxis) main.select('.y.axis').transition().call(yAxis)
} }
update(true, true)
draw(c3.data.targets) draw(c3.data.targets)
done() done()
...@@ -1358,7 +1375,7 @@ ...@@ -1358,7 +1375,7 @@
main.select('.y.axis').transition().call(yAxis) main.select('.y.axis').transition().call(yAxis)
} }
if (c3.data.targets.length > 0) update(true) if (c3.data.targets.length > 0) update(true, true)
} }
c3.selected = function (target) { c3.selected = function (target) {
......
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