Browse Source

Refactor for bar

pull/1/head
Masayuki Tanaka 12 years ago committed by masayuki
parent
commit
80d7640573
  1. 52
      c3.js

52
c3.js

@ -984,7 +984,7 @@
} }
function draw (targets) { function draw (targets) {
var barTargetsNum = getTargetsNum(isBarType), barWidth = 0, bar2Width = 0, barIndices, barX var barTargetsNum = getTargetsNum(isBarType), barIndices, barX, barY, barW, barH
var f, c var f, c
/*-- Main --*/ /*-- Main --*/
@ -1021,9 +1021,11 @@
.attr("r", __point_r) .attr("r", __point_r)
// Rects for each data // Rects for each data
barWidth = (xAxis.tickOffset()*2*0.6) / barTargetsNum
barIndices = getBarTargetIndices() barIndices = getBarTargetIndices()
barX = getBarX(barWidth, barTargetsNum, barIndices) barW = (xAxis.tickOffset()*2*0.6) / barTargetsNum
barH = function(d){ return height-y(d.value) }
barX = getBarX(barW, barTargetsNum, barIndices)
barY = function(d){ return y(d.value) }
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 })
@ -1036,9 +1038,9 @@
.enter().append("rect") .enter().append("rect")
.attr("class", function(d,i){ return "target-bar target-bar-" + i }) .attr("class", function(d,i){ return "target-bar target-bar-" + i })
.attr("x", barX) .attr("x", barX)
.attr("y", function(d){ return y(d.value) }) .attr("y", barY)
.attr("width", barWidth) .attr("width", barW)
.attr("height", function(d){ return height-y(d.value) }) .attr("height", barH)
//-- Main Update Section --// //-- Main Update Section --//
@ -1052,21 +1054,21 @@
.data(targets) .data(targets)
.filter(isLineType) .filter(isLineType)
.selectAll('circle') .selectAll('circle')
.data(function(d) { return d.values }) .data(function(d){ return d.values })
.transition() .transition()
.attr("cx", function(d) { return x(d.x) }) .attr("cx", function(d){ return x(d.x) })
.attr("cy", function(d) { return y(d.value) }) .attr("cy", function(d){ return y(d.value) })
main.selectAll(".target-bars") main.selectAll(".target-bars")
.data(targets) .data(targets)
.filter(isBarType) .filter(isBarType)
.selectAll('rect') .selectAll('rect')
.data(function(d) { return d.values }) .data(function(d){ return d.values })
.transition() .transition()
.attr("x", barX) .attr("x", barX)
.attr("y", function(d){ return y(d.value) }) .attr("y", barY)
.attr("width", barWidth) .attr("width", barW)
.attr("height", function(d){ return height-y(d.value) }) .attr("height", barH)
/*-- Context --*/ /*-- Context --*/
@ -1083,11 +1085,13 @@
.attr("class", function(d){ return "target-line target-line-" + d.id }) .attr("class", function(d){ return "target-line target-line-" + d.id })
.style("stroke", function(d) { return color(d.id) }) .style("stroke", function(d) { return color(d.id) })
.filter(isLineType) .filter(isLineType)
.attr("d", function (d) { return line2(d.values) }) .attr("d", function(d){ return line2(d.values) })
// Rects for each data // Rects for each data
bar2Width = (xAxis2.tickOffset()*2*0.6) / barTargetsNum barW = (xAxis2.tickOffset()*2*0.6) / barTargetsNum
barX = getBarX(bar2Width, barTargetsNum, barIndices) barH = function(d){ return height2-y2(d.value) }
barX = getBarX(barW, barTargetsNum, barIndices)
barY = function(d){ return y2(d.value) }
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 })
@ -1098,9 +1102,9 @@
.enter().append("rect") .enter().append("rect")
.attr("class", function(d,i){ return "target-bar target-bar-" + i }) .attr("class", function(d,i){ return "target-bar target-bar-" + i })
.attr("x", barX) .attr("x", barX)
.attr("y", function(d){ return y2(d.value) }) .attr("y", barY)
.attr("width", bar2Width) .attr("width", barW)
.attr("height", function(d){ return height2-y2(d.value) }) .attr("height", barH)
//-- Context Update Section --// //-- Context Update Section --//
@ -1108,18 +1112,18 @@
.data(targets) .data(targets)
.filter(isLineType) .filter(isLineType)
.transition() .transition()
.attr("d", function (d) { return line2(d.values) }) .attr("d", function(d){ return line2(d.values) })
context.selectAll(".target-bars") context.selectAll(".target-bars")
.data(targets) .data(targets)
.filter(isBarType) .filter(isBarType)
.selectAll('rect') .selectAll('rect')
.data(function(d) { return d.values }) .data(function(d){ return d.values })
.transition() .transition()
.attr("x", barX) .attr("x", barX)
.attr("y", function(d){ return y2(d.value) }) .attr("y", barY)
.attr("width", bar2Width) .attr("width", barW)
.attr("height", function(d){ return height2-y2(d.value) }) .attr("height", barH)
} }
/*-- Legend --*/ /*-- Legend --*/

Loading…
Cancel
Save