Commit 0635a52b authored by Masayuki Tanaka's avatar Masayuki Tanaka Committed by masayuki

Fix unload for bar

parent 80d76405
...@@ -394,6 +394,18 @@ ...@@ -394,6 +394,18 @@
return x(d.x) - barWidth * (barTargetsNum/2 - barIndices.indexOf(d.i)) return x(d.x) - barWidth * (barTargetsNum/2 - barIndices.indexOf(d.i))
} }
} }
function getBarY (scale) {
return function (d) { return scale(d.value) }
}
function getBarW (axis, barTargetsNum) {
return (axis.tickOffset()*2*0.6) / barTargetsNum
}
function getBarH (scale, height) {
return function (d) {
var h = height-scale(d.value)
return h < 0 ? 0 : h
}
}
function isLineType (d) { function isLineType (d) {
var id = (typeof d === 'string') ? d : d.id var id = (typeof d === 'string') ? d : d.id
return !(id in __data_types) || __data_types[id] === 'line' return !(id in __data_types) || __data_types[id] === 'line'
...@@ -897,7 +909,8 @@ ...@@ -897,7 +909,8 @@
function update (withTransition) { function update (withTransition) {
var xgrid, xgridData, xgridLine var xgrid, xgridData, xgridLine
var mainPath, mainCircle, mainBar, contextPath var mainPath, mainCircle, mainBar, contextPath
var barTargetsNum = getTargetsNum(isBarType), barWidth, barIndices, barX var barTargetsNum = getTargetsNum(isBarType), barIndices = getBarTargetIndices()
var barX, barY, barW, barH
var rectWidth var rectWidth
x.domain(brush.empty() ? x2.domain() : brush.extent()) x.domain(brush.empty() ? x2.domain() : brush.extent())
...@@ -952,20 +965,28 @@ ...@@ -952,20 +965,28 @@
.attr("cy", function(d) { return y(d.value) }) .attr("cy", function(d) { return y(d.value) })
// bars // bars
barWidth = (xAxis.tickOffset()*2*0.6) / barTargetsNum barW = getBarW(xAxis, barTargetsNum)
barIndices = getBarTargetIndices() barH = getBarH(y, height)
barX = getBarX(barWidth, barTargetsNum, barIndices) barX = getBarX(barW, barTargetsNum, barIndices)
barY = getBarY(y)
mainBar = main.selectAll('.target').selectAll('.target-bar').filter(isBarType) mainBar = main.selectAll('.target').selectAll('.target-bar').filter(isBarType)
if (withTransition) mainBar = mainBar.transition() if (withTransition) mainBar = mainBar.transition()
mainBar.attr("width", barWidth) mainBar.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH)
.attr("x", barX)
// subchart // subchart
if (__subchart_show) { if (__subchart_show) {
contextPath = context.selectAll('.target').selectAll('path').filter(isLineType) contextPath = context.selectAll('.target').selectAll('path').filter(isLineType)
if (withTransition) contextPath = contextPath.transition() if (withTransition) contextPath = contextPath.transition()
contextPath.attr("d", function(d){ return line2(d.values) }) contextPath.attr("d", function(d){ return line2(d.values) })
// bars
barW = getBarW(xAxis2, barTargetsNum)
barH = getBarH(y2, height2)
barX = getBarX(barW, barTargetsNum, barIndices)
barY = getBarY(y2)
contextBar = context.selectAll('.target').selectAll('.target-bar').filter(isBarType)
if (withTransition) contextBar = contextBar.transition()
contextBar.attr("x", barX).attr("y", barY).attr("width", barW).attr("height", barH)
} }
// circles for select // circles for select
...@@ -1022,10 +1043,10 @@ ...@@ -1022,10 +1043,10 @@
// Rects for each data // Rects for each data
barIndices = getBarTargetIndices() barIndices = getBarTargetIndices()
barW = (xAxis.tickOffset()*2*0.6) / barTargetsNum barW = getBarW(xAxis, barTargetsNum)
barH = function(d){ return height-y(d.value) } barH = getBarH(y, height)
barX = getBarX(barW, barTargetsNum, barIndices) barX = getBarX(barW, barTargetsNum, barIndices)
barY = function(d){ return y(d.value) } barY = getBarY(y)
f.append('g') f.append('g')
.attr("class", function(d){ return "target-bars target-bars-" + d.id }) .attr("class", function(d){ return "target-bars target-bars-" + d.id })
...@@ -1088,10 +1109,10 @@ ...@@ -1088,10 +1109,10 @@
.attr("d", function(d){ return line2(d.values) }) .attr("d", function(d){ return line2(d.values) })
// Rects for each data // Rects for each data
barW = (xAxis2.tickOffset()*2*0.6) / barTargetsNum barW = getBarW(xAxis2, barTargetsNum)
barH = function(d){ return height2-y2(d.value) } barH = getBarH(y2, height2)
barX = getBarX(barW, barTargetsNum, barIndices) barX = getBarX(barW, barTargetsNum, barIndices)
barY = function(d){ return y2(d.value) } barY = getBarY(y2)
c.append('g') c.append('g')
.attr("class", function(d){ return "target-bars target-bars-" + d.id }) .attr("class", function(d){ return "target-bars target-bars-" + d.id })
......
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