|
|
@ -48,28 +48,29 @@ c3_chart_internal_fn.updateXGrid = function (withoutUpdate) { |
|
|
|
'y2': $$.height |
|
|
|
'y2': $$.height |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
$$.xgrid = $$.main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) |
|
|
|
var xgrids = $$.main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) |
|
|
|
.data(xgridData); |
|
|
|
.data(xgridData); |
|
|
|
$$.xgrid.enter().append('line').attr("class", CLASS.xgrid); |
|
|
|
$$.xgrid = xgrids.enter().append('line').attr("class", CLASS.xgrid).merge(xgrids); |
|
|
|
if (!withoutUpdate) { |
|
|
|
if (!withoutUpdate) { |
|
|
|
$$.xgrid.attr($$.xgridAttr) |
|
|
|
$$.xgrid.attr($$.xgridAttr) |
|
|
|
.style("opacity", function () { return +d3.select(this).attr(config.axis_rotated ? 'y1' : 'x1') === (config.axis_rotated ? $$.height : 0) ? 0 : 1; }); |
|
|
|
.style("opacity", function () { return +d3.select(this).attr(config.axis_rotated ? 'y1' : 'x1') === (config.axis_rotated ? $$.height : 0) ? 0 : 1; }); |
|
|
|
} |
|
|
|
} |
|
|
|
$$.xgrid.exit().remove(); |
|
|
|
xgrids.exit().remove(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
c3_chart_internal_fn.updateYGrid = function () { |
|
|
|
c3_chart_internal_fn.updateYGrid = function () { |
|
|
|
var $$ = this, config = $$.config, |
|
|
|
var $$ = this, config = $$.config, |
|
|
|
gridValues = $$.yAxis.tickValues() || $$.y.ticks(config.grid_y_ticks); |
|
|
|
gridValues = $$.yAxis.tickValues() || $$.y.ticks(config.grid_y_ticks); |
|
|
|
$$.ygrid = $$.main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) |
|
|
|
var ygrids = $$.main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) |
|
|
|
.data(gridValues); |
|
|
|
.data(gridValues); |
|
|
|
$$.ygrid.enter().append('line') |
|
|
|
$$.ygrid = ygrids.enter().append('line') |
|
|
|
.attr('class', CLASS.ygrid); |
|
|
|
.attr('class', CLASS.ygrid) |
|
|
|
|
|
|
|
.merge(ygrids); |
|
|
|
$$.ygrid.attr("x1", config.axis_rotated ? $$.y : 0) |
|
|
|
$$.ygrid.attr("x1", config.axis_rotated ? $$.y : 0) |
|
|
|
.attr("x2", config.axis_rotated ? $$.y : $$.width) |
|
|
|
.attr("x2", config.axis_rotated ? $$.y : $$.width) |
|
|
|
.attr("y1", config.axis_rotated ? 0 : $$.y) |
|
|
|
.attr("y1", config.axis_rotated ? 0 : $$.y) |
|
|
|
.attr("y2", config.axis_rotated ? $$.height : $$.y); |
|
|
|
.attr("y2", config.axis_rotated ? $$.height : $$.y); |
|
|
|
$$.ygrid.exit().remove(); |
|
|
|
ygrids.exit().remove(); |
|
|
|
$$.smoothLines($$.ygrid, 'grid'); |
|
|
|
$$.smoothLines($$.ygrid, 'grid'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -87,7 +88,7 @@ c3_chart_internal_fn.yGridTextX = function (d) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.updateGrid = function (duration) { |
|
|
|
c3_chart_internal_fn.updateGrid = function (duration) { |
|
|
|
var $$ = this, main = $$.main, config = $$.config, |
|
|
|
var $$ = this, main = $$.main, config = $$.config, |
|
|
|
xgridLine, ygridLine, yv; |
|
|
|
xgridLine, xgridLineEnter, ygridLine, ygridLineEnter, yv; |
|
|
|
|
|
|
|
|
|
|
|
// hide if arc type
|
|
|
|
// hide if arc type
|
|
|
|
$$.grid.style('visibility', $$.hasArcType() ? 'hidden' : 'visible'); |
|
|
|
$$.grid.style('visibility', $$.hasArcType() ? 'hidden' : 'visible'); |
|
|
@ -96,23 +97,24 @@ c3_chart_internal_fn.updateGrid = function (duration) { |
|
|
|
if (config.grid_x_show) { |
|
|
|
if (config.grid_x_show) { |
|
|
|
$$.updateXGrid(); |
|
|
|
$$.updateXGrid(); |
|
|
|
} |
|
|
|
} |
|
|
|
$$.xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) |
|
|
|
xgridLine = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) |
|
|
|
.data(config.grid_x_lines); |
|
|
|
.data(config.grid_x_lines); |
|
|
|
// enter
|
|
|
|
// enter
|
|
|
|
xgridLine = $$.xgridLines.enter().append('g') |
|
|
|
xgridLineEnter = xgridLine.enter().append('g') |
|
|
|
.attr("class", function (d) { return CLASS.xgridLine + (d['class'] ? ' ' + d['class'] : ''); }); |
|
|
|
.attr("class", function (d) { return CLASS.xgridLine + (d['class'] ? ' ' + d['class'] : ''); }); |
|
|
|
xgridLine.append('line') |
|
|
|
xgridLineEnter.append('line') |
|
|
|
.style("opacity", 0); |
|
|
|
.style("opacity", 0); |
|
|
|
xgridLine.append('text') |
|
|
|
xgridLineEnter.append('text') |
|
|
|
.attr("text-anchor", $$.gridTextAnchor) |
|
|
|
.attr("text-anchor", $$.gridTextAnchor) |
|
|
|
.attr("transform", config.axis_rotated ? "" : "rotate(-90)") |
|
|
|
.attr("transform", config.axis_rotated ? "" : "rotate(-90)") |
|
|
|
.attr('dx', $$.gridTextDx) |
|
|
|
.attr('dx', $$.gridTextDx) |
|
|
|
.attr('dy', -5) |
|
|
|
.attr('dy', -5) |
|
|
|
.style("opacity", 0); |
|
|
|
.style("opacity", 0); |
|
|
|
// udpate
|
|
|
|
// udpate
|
|
|
|
|
|
|
|
$$.xgridLines = xgridLineEnter.merge(xgridLine); |
|
|
|
// done in d3.transition() of the end of this function
|
|
|
|
// done in d3.transition() of the end of this function
|
|
|
|
// exit
|
|
|
|
// exit
|
|
|
|
$$.xgridLines.exit().transition().duration(duration) |
|
|
|
xgridLine.exit().transition().duration(duration) |
|
|
|
.style("opacity", 0) |
|
|
|
.style("opacity", 0) |
|
|
|
.remove(); |
|
|
|
.remove(); |
|
|
|
|
|
|
|
|
|
|
@ -120,20 +122,21 @@ c3_chart_internal_fn.updateGrid = function (duration) { |
|
|
|
if (config.grid_y_show) { |
|
|
|
if (config.grid_y_show) { |
|
|
|
$$.updateYGrid(); |
|
|
|
$$.updateYGrid(); |
|
|
|
} |
|
|
|
} |
|
|
|
$$.ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) |
|
|
|
ygridLine = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) |
|
|
|
.data(config.grid_y_lines); |
|
|
|
.data(config.grid_y_lines); |
|
|
|
// enter
|
|
|
|
// enter
|
|
|
|
ygridLine = $$.ygridLines.enter().append('g') |
|
|
|
ygridLineEnter = ygridLine.enter().append('g') |
|
|
|
.attr("class", function (d) { return CLASS.ygridLine + (d['class'] ? ' ' + d['class'] : ''); }); |
|
|
|
.attr("class", function (d) { return CLASS.ygridLine + (d['class'] ? ' ' + d['class'] : ''); }); |
|
|
|
ygridLine.append('line') |
|
|
|
ygridLineEnter.append('line') |
|
|
|
.style("opacity", 0); |
|
|
|
.style("opacity", 0); |
|
|
|
ygridLine.append('text') |
|
|
|
ygridLineEnter.append('text') |
|
|
|
.attr("text-anchor", $$.gridTextAnchor) |
|
|
|
.attr("text-anchor", $$.gridTextAnchor) |
|
|
|
.attr("transform", config.axis_rotated ? "rotate(-90)" : "") |
|
|
|
.attr("transform", config.axis_rotated ? "rotate(-90)" : "") |
|
|
|
.attr('dx', $$.gridTextDx) |
|
|
|
.attr('dx', $$.gridTextDx) |
|
|
|
.attr('dy', -5) |
|
|
|
.attr('dy', -5) |
|
|
|
.style("opacity", 0); |
|
|
|
.style("opacity", 0); |
|
|
|
// update
|
|
|
|
// update
|
|
|
|
|
|
|
|
$$.ygridLines = ygridLineEnter.merge(ygridLine); |
|
|
|
yv = $$.yv.bind($$); |
|
|
|
yv = $$.yv.bind($$); |
|
|
|
$$.ygridLines.select('line') |
|
|
|
$$.ygridLines.select('line') |
|
|
|
.transition().duration(duration) |
|
|
|
.transition().duration(duration) |
|
|
@ -149,7 +152,7 @@ c3_chart_internal_fn.updateGrid = function (duration) { |
|
|
|
.text(function (d) { return d.text; }) |
|
|
|
.text(function (d) { return d.text; }) |
|
|
|
.style("opacity", 1); |
|
|
|
.style("opacity", 1); |
|
|
|
// exit
|
|
|
|
// exit
|
|
|
|
$$.ygridLines.exit().transition().duration(duration) |
|
|
|
ygridLine.exit().transition().duration(duration) |
|
|
|
.style("opacity", 0) |
|
|
|
.style("opacity", 0) |
|
|
|
.remove(); |
|
|
|
.remove(); |
|
|
|
}; |
|
|
|
}; |
|
|
|