|
|
@ -3,24 +3,40 @@ import { c3_chart_internal_fn } from './core'; |
|
|
|
import { isFunction } from './util'; |
|
|
|
import { isFunction } from './util'; |
|
|
|
|
|
|
|
|
|
|
|
c3_chart_internal_fn.initBrush = function () { |
|
|
|
c3_chart_internal_fn.initBrush = function () { |
|
|
|
var $$ = this, d3 = $$.d3; |
|
|
|
var $$ = this, d3 = $$.d3, currentScale; |
|
|
|
$$.brush = d3.brush().on("brush", function () { $$.redrawForBrush(); }); |
|
|
|
// TODO: dynamically change brushY/brushX according to axis_rotated.
|
|
|
|
|
|
|
|
$$.brush = ($$.config.axis_rotated ? d3.brushY() : d3.brushX()).on("brush", function () { |
|
|
|
|
|
|
|
$$.redrawForBrush(); |
|
|
|
|
|
|
|
}); |
|
|
|
$$.brush.update = function () { |
|
|
|
$$.brush.update = function () { |
|
|
|
if ($$.context) { $$.context.select('.' + CLASS.brush).call(this); } |
|
|
|
var brush; |
|
|
|
|
|
|
|
if ($$.context) { |
|
|
|
|
|
|
|
$$.context.select('.' + CLASS.brush).call(this); |
|
|
|
|
|
|
|
} |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// TODO: fix
|
|
|
|
|
|
|
|
$$.brush.scale = function (scale) { |
|
|
|
$$.brush.scale = function (scale) { |
|
|
|
|
|
|
|
currentScale = scale; |
|
|
|
|
|
|
|
var range = scale.range(), |
|
|
|
|
|
|
|
extent; |
|
|
|
if ($$.config.axis_rotated) { |
|
|
|
if ($$.config.axis_rotated) { |
|
|
|
d3.brushY().extent([[0, scale.range()[0]], [40, scale.range()[1]]]); |
|
|
|
extent = [[0, range[0]], [$$.width2, range[1]]]; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
d3.brushX().extent([[scale.range()[0], 0], [scale.range()[1], 40]]); |
|
|
|
extent = [[range[0], 0], [range[1], $$.height2]]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$$.brush.extent(extent).update(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
$$.brush.selection = function () { |
|
|
|
|
|
|
|
return d3.brushSelection($$.context.select('.' + CLASS.brush).node()); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
$$.brush.selectionAsValue = function () { |
|
|
|
|
|
|
|
var selection = $$.brush.selection() || [0,0]; |
|
|
|
|
|
|
|
return [currentScale.invert(selection[0]), currentScale.invert(selection[1])]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// TODO: fix
|
|
|
|
|
|
|
|
$$.brush.empty = function () { |
|
|
|
$$.brush.empty = function () { |
|
|
|
return true; |
|
|
|
var selection = $$.brush.selection(); |
|
|
|
|
|
|
|
return !selection || selection[0] === selection[1]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.initSubchart = function () { |
|
|
|
c3_chart_internal_fn.initSubchart = function () { |
|
|
@ -59,7 +75,7 @@ c3_chart_internal_fn.initSubchart = function () { |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { |
|
|
|
c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { |
|
|
|
var $$ = this, context = $$.context, config = $$.config, |
|
|
|
var $$ = this, context = $$.context, config = $$.config, |
|
|
|
contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate, |
|
|
|
contextLineEnter, contextLine, contextBarEnter, contextBar, |
|
|
|
classChartBar = $$.classChartBar.bind($$), |
|
|
|
classChartBar = $$.classChartBar.bind($$), |
|
|
|
classBars = $$.classBars.bind($$), |
|
|
|
classBars = $$.classBars.bind($$), |
|
|
|
classChartLine = $$.classChartLine.bind($$), |
|
|
|
classChartLine = $$.classChartLine.bind($$), |
|
|
@ -68,22 +84,22 @@ c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { |
|
|
|
|
|
|
|
|
|
|
|
if (config.subchart_show) { |
|
|
|
if (config.subchart_show) { |
|
|
|
//-- Bar --//
|
|
|
|
//-- Bar --//
|
|
|
|
contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) |
|
|
|
contextBar = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) |
|
|
|
.data(targets) |
|
|
|
.data(targets); |
|
|
|
.attr('class', classChartBar); |
|
|
|
contextBarEnter = contextBar.enter().append('g') |
|
|
|
contextBarEnter = contextBarUpdate.enter().append('g') |
|
|
|
.style('opacity', 0); |
|
|
|
.style('opacity', 0) |
|
|
|
contextBarEnter.merge(contextBar) |
|
|
|
.attr('class', classChartBar); |
|
|
|
.attr('class', classChartBar); |
|
|
|
// Bars for each data
|
|
|
|
// Bars for each data
|
|
|
|
contextBarEnter.append('g') |
|
|
|
contextBarEnter.append('g') |
|
|
|
.attr("class", classBars); |
|
|
|
.attr("class", classBars); |
|
|
|
|
|
|
|
|
|
|
|
//-- Line --//
|
|
|
|
//-- Line --//
|
|
|
|
contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) |
|
|
|
contextLine = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) |
|
|
|
.data(targets) |
|
|
|
.data(targets); |
|
|
|
.attr('class', classChartLine); |
|
|
|
contextLineEnter = contextLine.enter().append('g') |
|
|
|
contextLineEnter = contextLineUpdate.enter().append('g') |
|
|
|
.style('opacity', 0); |
|
|
|
.style('opacity', 0) |
|
|
|
contextLineEnter.merge(contextLine) |
|
|
|
.attr('class', classChartLine); |
|
|
|
.attr('class', classChartLine); |
|
|
|
// Lines for each data
|
|
|
|
// Lines for each data
|
|
|
|
contextLineEnter.append("g") |
|
|
|
contextLineEnter.append("g") |
|
|
@ -99,17 +115,17 @@ c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.updateBarForSubchart = function (durationForExit) { |
|
|
|
c3_chart_internal_fn.updateBarForSubchart = function (durationForExit) { |
|
|
|
var $$ = this; |
|
|
|
var $$ = this; |
|
|
|
$$.contextBar = $$.context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) |
|
|
|
var contextBar = $$.context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) |
|
|
|
.data($$.barData.bind($$)); |
|
|
|
.data($$.barData.bind($$)); |
|
|
|
$$.contextBar.enter().append('path') |
|
|
|
var contextBarEnter = contextBar.enter().append('path') |
|
|
|
.attr("class", $$.classBar.bind($$)) |
|
|
|
.attr("class", $$.classBar.bind($$)) |
|
|
|
.style("stroke", 'none') |
|
|
|
.style("stroke", 'none') |
|
|
|
.style("fill", $$.color); |
|
|
|
.style("fill", $$.color); |
|
|
|
$$.contextBar |
|
|
|
var contextBarExit = contextBar.exit().transition().duration(durationForExit) |
|
|
|
.style("opacity", $$.initialOpacity.bind($$)); |
|
|
|
|
|
|
|
$$.contextBar.exit().transition().duration(durationForExit) |
|
|
|
|
|
|
|
.style('opacity', 0) |
|
|
|
.style('opacity', 0) |
|
|
|
.remove(); |
|
|
|
.remove(); |
|
|
|
|
|
|
|
$$.contextBar = contextBarEnter.merge(contextBar) |
|
|
|
|
|
|
|
.style("opacity", $$.initialOpacity.bind($$)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.redrawBarForSubchart = function (drawBarOnSub, withTransition, duration) { |
|
|
|
c3_chart_internal_fn.redrawBarForSubchart = function (drawBarOnSub, withTransition, duration) { |
|
|
|
(withTransition ? this.contextBar.transition(Math.random().toString()).duration(duration) : this.contextBar) |
|
|
|
(withTransition ? this.contextBar.transition(Math.random().toString()).duration(duration) : this.contextBar) |
|
|
@ -118,16 +134,16 @@ c3_chart_internal_fn.redrawBarForSubchart = function (drawBarOnSub, withTransiti |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.updateLineForSubchart = function (durationForExit) { |
|
|
|
c3_chart_internal_fn.updateLineForSubchart = function (durationForExit) { |
|
|
|
var $$ = this; |
|
|
|
var $$ = this; |
|
|
|
$$.contextLine = $$.context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) |
|
|
|
var contextLine = $$.context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) |
|
|
|
.data($$.lineData.bind($$)); |
|
|
|
.data($$.lineData.bind($$)); |
|
|
|
$$.contextLine.enter().append('path') |
|
|
|
var contextLineEnter = contextLine.enter().append('path') |
|
|
|
.attr('class', $$.classLine.bind($$)) |
|
|
|
.attr('class', $$.classLine.bind($$)) |
|
|
|
.style('stroke', $$.color); |
|
|
|
.style('stroke', $$.color); |
|
|
|
$$.contextLine |
|
|
|
var contextLineExit = contextLine.exit().transition().duration(durationForExit) |
|
|
|
.style("opacity", $$.initialOpacity.bind($$)); |
|
|
|
|
|
|
|
$$.contextLine.exit().transition().duration(durationForExit) |
|
|
|
|
|
|
|
.style('opacity', 0) |
|
|
|
.style('opacity', 0) |
|
|
|
.remove(); |
|
|
|
.remove(); |
|
|
|
|
|
|
|
$$.contextLine = contextLineEnter.merge(contextLine) |
|
|
|
|
|
|
|
.style("opacity", $$.initialOpacity.bind($$)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.redrawLineForSubchart = function (drawLineOnSub, withTransition, duration) { |
|
|
|
c3_chart_internal_fn.redrawLineForSubchart = function (drawLineOnSub, withTransition, duration) { |
|
|
|
(withTransition ? this.contextLine.transition(Math.random().toString()).duration(duration) : this.contextLine) |
|
|
|
(withTransition ? this.contextLine.transition(Math.random().toString()).duration(duration) : this.contextLine) |
|
|
@ -136,17 +152,17 @@ c3_chart_internal_fn.redrawLineForSubchart = function (drawLineOnSub, withTransi |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.updateAreaForSubchart = function (durationForExit) { |
|
|
|
c3_chart_internal_fn.updateAreaForSubchart = function (durationForExit) { |
|
|
|
var $$ = this, d3 = $$.d3; |
|
|
|
var $$ = this, d3 = $$.d3; |
|
|
|
$$.contextArea = $$.context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) |
|
|
|
var contextArea = $$.context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) |
|
|
|
.data($$.lineData.bind($$)); |
|
|
|
.data($$.lineData.bind($$)); |
|
|
|
$$.contextArea.enter().append('path') |
|
|
|
var contextAreaEnter = contextArea.enter().append('path') |
|
|
|
.attr("class", $$.classArea.bind($$)) |
|
|
|
.attr("class", $$.classArea.bind($$)) |
|
|
|
.style("fill", $$.color) |
|
|
|
.style("fill", $$.color) |
|
|
|
.style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); |
|
|
|
.style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); |
|
|
|
$$.contextArea |
|
|
|
var contextAreaExit = contextArea.exit().transition().duration(durationForExit) |
|
|
|
.style("opacity", 0); |
|
|
|
|
|
|
|
$$.contextArea.exit().transition().duration(durationForExit) |
|
|
|
|
|
|
|
.style('opacity', 0) |
|
|
|
.style('opacity', 0) |
|
|
|
.remove(); |
|
|
|
.remove(); |
|
|
|
|
|
|
|
$$.contextArea = contextAreaEnter.merge(contextArea) |
|
|
|
|
|
|
|
.style("opacity", 0); |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.redrawAreaForSubchart = function (drawAreaOnSub, withTransition, duration) { |
|
|
|
c3_chart_internal_fn.redrawAreaForSubchart = function (drawAreaOnSub, withTransition, duration) { |
|
|
|
(withTransition ? this.contextArea.transition(Math.random().toString()).duration(duration) : this.contextArea) |
|
|
|
(withTransition ? this.contextArea.transition(Math.random().toString()).duration(duration) : this.contextArea) |
|
|
|