Commit 18a39d58 authored by GermainBergeron's avatar GermainBergeron

Fixed build

Added c3.js & c3.min.js
parent ce96ac07
...@@ -4,17 +4,17 @@ ...@@ -4,17 +4,17 @@
/*global define, module, exports, require */ /*global define, module, exports, require */
var c3 = { version: "0.4.10" }; var c3 = { version: "0.4.10" };
var c3_chart_fn, var c3_chart_fn,
c3_chart_internal_fn, c3_chart_internal_fn,
c3_chart_internal_axis_fn; c3_chart_internal_axis_fn;
function API(owner) { function API(owner) {
this.owner = owner; this.owner = owner;
} }
function inherit(base, derived) { function inherit(base, derived) {
if (Object.create) { if (Object.create) {
derived.prototype = Object.create(base.prototype); derived.prototype = Object.create(base.prototype);
} else { } else {
...@@ -22,17 +22,17 @@ ...@@ -22,17 +22,17 @@
f.prototype = base.prototype; f.prototype = base.prototype;
derived.prototype = new f(); derived.prototype = new f();
} }
derived.prototype.constructor = derived; derived.prototype.constructor = derived;
return derived; return derived;
} }
function Chart(config) { function Chart(config) {
var $$ = this.internal = new ChartInternal(this); var $$ = this.internal = new ChartInternal(this);
$$.loadConfig(config); $$.loadConfig(config);
$$.init(); $$.init();
// bind "this" to nested API // bind "this" to nested API
(function bindThis(fn, target, argThis) { (function bindThis(fn, target, argThis) {
Object.keys(fn).forEach(function (key) { Object.keys(fn).forEach(function (key) {
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
}); });
})(c3_chart_fn, this, this); })(c3_chart_fn, this, this);
} }
function ChartInternal(api) { function ChartInternal(api) {
var $$ = this; var $$ = this;
$$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined; $$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined;
...@@ -53,11 +53,11 @@ ...@@ -53,11 +53,11 @@
$$.cache = {}; $$.cache = {};
$$.axes = {}; $$.axes = {};
} }
c3.generate = function (config) { c3.generate = function (config) {
return new Chart(config); return new Chart(config);
}; };
c3.chart = { c3.chart = {
fn: Chart.prototype, fn: Chart.prototype,
internal: { internal: {
...@@ -70,12 +70,12 @@ ...@@ -70,12 +70,12 @@
c3_chart_fn = c3.chart.fn; c3_chart_fn = c3.chart.fn;
c3_chart_internal_fn = c3.chart.internal.fn; c3_chart_internal_fn = c3.chart.internal.fn;
c3_chart_internal_axis_fn = c3.chart.internal.axis.fn; c3_chart_internal_axis_fn = c3.chart.internal.axis.fn;
c3_chart_internal_fn.init = function () { c3_chart_internal_fn.init = function () {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
$$.initParams(); $$.initParams();
if (config.data_url) { if (config.data_url) {
$$.convertUrlToData(config.data_url, config.data_mimeType, config.data_keys, $$.initWithData); $$.convertUrlToData(config.data_url, config.data_mimeType, config.data_keys, $$.initWithData);
} }
...@@ -92,10 +92,10 @@ ...@@ -92,10 +92,10 @@
throw Error('url or json or rows or columns is required.'); throw Error('url or json or rows or columns is required.');
} }
}; };
c3_chart_internal_fn.initParams = function () { c3_chart_internal_fn.initParams = function () {
var $$ = this, d3 = $$.d3, config = $$.config; var $$ = this, d3 = $$.d3, config = $$.config;
// MEMO: clipId needs to be unique because it conflicts when multiple charts exist // MEMO: clipId needs to be unique because it conflicts when multiple charts exist
$$.clipId = "c3-" + (+new Date()) + '-clip', $$.clipId = "c3-" + (+new Date()) + '-clip',
$$.clipIdForXAxis = $$.clipId + '-xaxis', $$.clipIdForXAxis = $$.clipId + '-xaxis',
...@@ -107,17 +107,17 @@ ...@@ -107,17 +107,17 @@
$$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis);
$$.clipPathForGrid = $$.getClipPath($$.clipIdForGrid), $$.clipPathForGrid = $$.getClipPath($$.clipIdForGrid),
$$.clipPathForSubchart = $$.getClipPath($$.clipIdForSubchart), $$.clipPathForSubchart = $$.getClipPath($$.clipIdForSubchart),
$$.dragStart = null; $$.dragStart = null;
$$.dragging = false; $$.dragging = false;
$$.flowing = false; $$.flowing = false;
$$.cancelClick = false; $$.cancelClick = false;
$$.mouseover = false; $$.mouseover = false;
$$.transiting = false; $$.transiting = false;
$$.color = $$.generateColor(); $$.color = $$.generateColor();
$$.levelColor = $$.generateLevelColor(); $$.levelColor = $$.generateLevelColor();
$$.dataTimeFormat = config.data_xLocaltime ? d3.time.format : d3.time.format.utc; $$.dataTimeFormat = config.data_xLocaltime ? d3.time.format : d3.time.format.utc;
$$.axisTimeFormat = config.axis_x_localtime ? d3.time.format : d3.time.format.utc; $$.axisTimeFormat = config.axis_x_localtime ? d3.time.format : d3.time.format.utc;
$$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([ $$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([
...@@ -130,17 +130,17 @@ ...@@ -130,17 +130,17 @@
["%-m/%-d", function (d) { return d.getMonth(); }], ["%-m/%-d", function (d) { return d.getMonth(); }],
["%Y/%-m/%-d", function () { return true; }] ["%Y/%-m/%-d", function () { return true; }]
]); ]);
$$.hiddenTargetIds = []; $$.hiddenTargetIds = [];
$$.hiddenLegendIds = []; $$.hiddenLegendIds = [];
$$.focusedTargetIds = []; $$.focusedTargetIds = [];
$$.defocusedTargetIds = []; $$.defocusedTargetIds = [];
$$.xOrient = config.axis_rotated ? "left" : "bottom"; $$.xOrient = config.axis_rotated ? "left" : "bottom";
$$.yOrient = config.axis_rotated ? (config.axis_y_inner ? "top" : "bottom") : (config.axis_y_inner ? "right" : "left"); $$.yOrient = config.axis_rotated ? (config.axis_y_inner ? "top" : "bottom") : (config.axis_y_inner ? "right" : "left");
$$.y2Orient = config.axis_rotated ? (config.axis_y2_inner ? "bottom" : "top") : (config.axis_y2_inner ? "left" : "right"); $$.y2Orient = config.axis_rotated ? (config.axis_y2_inner ? "bottom" : "top") : (config.axis_y2_inner ? "left" : "right");
$$.subXOrient = config.axis_rotated ? "left" : "bottom"; $$.subXOrient = config.axis_rotated ? "left" : "bottom";
$$.isLegendRight = config.legend_position === 'right'; $$.isLegendRight = config.legend_position === 'right';
$$.isLegendInset = config.legend_position === 'inset'; $$.isLegendInset = config.legend_position === 'inset';
$$.isLegendTop = config.legend_inset_anchor === 'top-left' || config.legend_inset_anchor === 'top-right'; $$.isLegendTop = config.legend_inset_anchor === 'top-left' || config.legend_inset_anchor === 'top-right';
...@@ -148,24 +148,24 @@ ...@@ -148,24 +148,24 @@
$$.legendStep = 0; $$.legendStep = 0;
$$.legendItemWidth = 0; $$.legendItemWidth = 0;
$$.legendItemHeight = 0; $$.legendItemHeight = 0;
$$.currentMaxTickWidths = { $$.currentMaxTickWidths = {
x: 0, x: 0,
y: 0, y: 0,
y2: 0 y2: 0
}; };
$$.rotated_padding_left = 30; $$.rotated_padding_left = 30;
$$.rotated_padding_right = config.axis_rotated && !config.axis_x_show ? 0 : 30; $$.rotated_padding_right = config.axis_rotated && !config.axis_x_show ? 0 : 30;
$$.rotated_padding_top = 5; $$.rotated_padding_top = 5;
$$.withoutFadeIn = {}; $$.withoutFadeIn = {};
$$.intervalForObserveInserted = undefined; $$.intervalForObserveInserted = undefined;
$$.axes.subx = d3.selectAll([]); // needs when excluding subchart.js $$.axes.subx = d3.selectAll([]); // needs when excluding subchart.js
}; };
c3_chart_internal_fn.initChartElements = function () { c3_chart_internal_fn.initChartElements = function () {
if (this.initBar) { this.initBar(); } if (this.initBar) { this.initBar(); }
if (this.initLine) { this.initLine(); } if (this.initLine) { this.initLine(); }
...@@ -173,17 +173,17 @@ ...@@ -173,17 +173,17 @@
if (this.initGauge) { this.initGauge(); } if (this.initGauge) { this.initGauge(); }
if (this.initText) { this.initText(); } if (this.initText) { this.initText(); }
}; };
c3_chart_internal_fn.initWithData = function (data) { c3_chart_internal_fn.initWithData = function (data) {
var $$ = this, d3 = $$.d3, config = $$.config; var $$ = this, d3 = $$.d3, config = $$.config;
var defs, main, binding = true; var defs, main, binding = true;
$$.axis = new Axis($$); $$.axis = new Axis($$);
if ($$.initPie) { $$.initPie(); } if ($$.initPie) { $$.initPie(); }
if ($$.initBrush) { $$.initBrush(); } if ($$.initBrush) { $$.initBrush(); }
if ($$.initZoom) { $$.initZoom(); } if ($$.initZoom) { $$.initZoom(); }
if (!config.bindto) { if (!config.bindto) {
$$.selectChart = d3.selectAll([]); $$.selectChart = d3.selectAll([]);
} }
...@@ -199,15 +199,15 @@ ...@@ -199,15 +199,15 @@
binding = false; binding = false;
} }
$$.selectChart.html("").classed("c3", true); $$.selectChart.html("").classed("c3", true);
// Init data as targets // Init data as targets
$$.data.xs = {}; $$.data.xs = {};
$$.data.targets = $$.convertDataToTargets(data); $$.data.targets = $$.convertDataToTargets(data);
if (config.data_filter) { if (config.data_filter) {
$$.data.targets = $$.data.targets.filter(config.data_filter); $$.data.targets = $$.data.targets.filter(config.data_filter);
} }
// Set targets to hide if needed // Set targets to hide if needed
if (config.data_hide) { if (config.data_hide) {
$$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide); $$.addHiddenTargetIds(config.data_hide === true ? $$.mapToIds($$.data.targets) : config.data_hide);
...@@ -215,16 +215,16 @@ ...@@ -215,16 +215,16 @@
if (config.legend_hide) { if (config.legend_hide) {
$$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide); $$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide);
} }
// when gauge, hide legend // TODO: fix // when gauge, hide legend // TODO: fix
if ($$.hasType('gauge')) { if ($$.hasType('gauge')) {
config.legend_show = false; config.legend_show = false;
} }
// Init sizes and scales // Init sizes and scales
$$.updateSizes(); $$.updateSizes();
$$.updateScales(); $$.updateScales();
// Set domains for each scale // Set domains for each scale
$$.x.domain(d3.extent($$.getXDomain($$.data.targets))); $$.x.domain(d3.extent($$.getXDomain($$.data.targets)));
$$.y.domain($$.getYDomain($$.data.targets, 'y')); $$.y.domain($$.getYDomain($$.data.targets, 'y'));
...@@ -232,22 +232,22 @@ ...@@ -232,22 +232,22 @@
$$.subX.domain($$.x.domain()); $$.subX.domain($$.x.domain());
$$.subY.domain($$.y.domain()); $$.subY.domain($$.y.domain());
$$.subY2.domain($$.y2.domain()); $$.subY2.domain($$.y2.domain());
// Save original x domain for zoom update // Save original x domain for zoom update
$$.orgXDomain = $$.x.domain(); $$.orgXDomain = $$.x.domain();
// Set initialized scales to brush and zoom // Set initialized scales to brush and zoom
if ($$.brush) { $$.brush.scale($$.subX); } if ($$.brush) { $$.brush.scale($$.subX); }
if (config.zoom_enabled) { $$.zoom.scale($$.x); } if (config.zoom_enabled) { $$.zoom.scale($$.x); }
/*-- Basic Elements --*/ /*-- Basic Elements --*/
// Define svgs // Define svgs
$$.svg = $$.selectChart.append("svg") $$.svg = $$.selectChart.append("svg")
.style("overflow", "hidden") .style("overflow", "hidden")
.on('mouseenter', function () { return config.onmouseover.call($$); }) .on('mouseenter', function () { return config.onmouseover.call($$); })
.on('mouseleave', function () { return config.onmouseout.call($$); }); .on('mouseleave', function () { return config.onmouseout.call($$); });
// Define defs // Define defs
defs = $$.svg.append("defs"); defs = $$.svg.append("defs");
$$.clipChart = $$.appendClip(defs, $$.clipId); $$.clipChart = $$.appendClip(defs, $$.clipId);
...@@ -256,43 +256,43 @@ ...@@ -256,43 +256,43 @@
$$.clipGrid = $$.appendClip(defs, $$.clipIdForGrid); $$.clipGrid = $$.appendClip(defs, $$.clipIdForGrid);
$$.clipSubchart = $$.appendClip(defs, $$.clipIdForSubchart); $$.clipSubchart = $$.appendClip(defs, $$.clipIdForSubchart);
$$.updateSvgSize(); $$.updateSvgSize();
// Define regions // Define regions
main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main'));
if ($$.initSubchart) { $$.initSubchart(); } if ($$.initSubchart) { $$.initSubchart(); }
if ($$.initTooltip) { $$.initTooltip(); } if ($$.initTooltip) { $$.initTooltip(); }
if ($$.initLegend) { $$.initLegend(); } if ($$.initLegend) { $$.initLegend(); }
if ($$.initTitle) { $$.initTitle(); } if ($$.initTitle) { $$.initTitle(); }
/*-- Main Region --*/ /*-- Main Region --*/
// text when empty // text when empty
main.append("text") main.append("text")
.attr("class", CLASS.text + ' ' + CLASS.empty) .attr("class", CLASS.text + ' ' + CLASS.empty)
.attr("text-anchor", "middle") // horizontal centering of text at x position in all browsers. .attr("text-anchor", "middle") // horizontal centering of text at x position in all browsers.
.attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE. .attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE.
// Regions // Regions
$$.initRegion(); $$.initRegion();
// Grids // Grids
$$.initGrid(); $$.initGrid();
// Define g for chart area // Define g for chart area
main.append('g') main.append('g')
.attr("clip-path", $$.clipPath) .attr("clip-path", $$.clipPath)
.attr('class', CLASS.chart); .attr('class', CLASS.chart);
// Grid lines // Grid lines
if (config.grid_lines_front) { $$.initGridLines(); } if (config.grid_lines_front) { $$.initGridLines(); }
// Cover whole with rects for events // Cover whole with rects for events
$$.initEventRect(); $$.initEventRect();
// Define g for chart // Define g for chart
$$.initChartElements(); $$.initChartElements();
// if zoom privileged, insert rect to forefront // if zoom privileged, insert rect to forefront
// TODO: is this needed? // TODO: is this needed?
main.insert('rect', config.zoom_privileged ? null : 'g.' + CLASS.regions) main.insert('rect', config.zoom_privileged ? null : 'g.' + CLASS.regions)
...@@ -301,16 +301,16 @@ ...@@ -301,16 +301,16 @@
.attr('height', $$.height) .attr('height', $$.height)
.style('opacity', 0) .style('opacity', 0)
.on("dblclick.zoom", null); .on("dblclick.zoom", null);
// Set default extent if defined // Set default extent if defined
if (config.axis_x_extent) { $$.brush.extent($$.getDefaultExtent()); } if (config.axis_x_extent) { $$.brush.extent($$.getDefaultExtent()); }
// Add Axis // Add Axis
$$.axis.init(); $$.axis.init();
// Set targets // Set targets
$$.updateTargets($$.data.targets); $$.updateTargets($$.data.targets);
// Draw with targets // Draw with targets
if (binding) { if (binding) {
$$.updateDimension(); $$.updateDimension();
...@@ -323,7 +323,7 @@ ...@@ -323,7 +323,7 @@
withTransitionForAxis: false withTransitionForAxis: false
}); });
} }
// Bind resize event // Bind resize event
if (window.onresize == null) { if (window.onresize == null) {
window.onresize = $$.generateResize(); window.onresize = $$.generateResize();
...@@ -339,11 +339,11 @@ ...@@ -339,11 +339,11 @@
config.onresized.call($$); config.onresized.call($$);
}); });
} }
// export element of the chart // export element of the chart
$$.api.element = $$.selectChart.node(); $$.api.element = $$.selectChart.node();
}; };
c3_chart_internal_fn.smoothLines = function (el, type) { c3_chart_internal_fn.smoothLines = function (el, type) {
var $$ = this; var $$ = this;
if (type === 'grid') { if (type === 'grid') {
...@@ -362,8 +362,8 @@ ...@@ -362,8 +362,8 @@
}); });
} }
}; };
c3_chart_internal_fn.updateSizes = function () { c3_chart_internal_fn.updateSizes = function () {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
var legendHeight = $$.legend ? $$.getLegendHeight() : 0, var legendHeight = $$.legend ? $$.getLegendHeight() : 0,
...@@ -372,10 +372,10 @@ ...@@ -372,10 +372,10 @@
hasArc = $$.hasArcType(), hasArc = $$.hasArcType(),
xAxisHeight = config.axis_rotated || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), xAxisHeight = config.axis_rotated || hasArc ? 0 : $$.getHorizontalAxisHeight('x'),
subchartHeight = config.subchart_show && !hasArc ? (config.subchart_size_height + xAxisHeight) : 0; subchartHeight = config.subchart_show && !hasArc ? (config.subchart_size_height + xAxisHeight) : 0;
$$.currentWidth = $$.getCurrentWidth(); $$.currentWidth = $$.getCurrentWidth();
$$.currentHeight = $$.getCurrentHeight(); $$.currentHeight = $$.getCurrentHeight();
// for main // for main
$$.margin = config.axis_rotated ? { $$.margin = config.axis_rotated ? {
top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(),
...@@ -388,7 +388,7 @@ ...@@ -388,7 +388,7 @@
bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(),
left: hasArc ? 0 : $$.getCurrentPaddingLeft() left: hasArc ? 0 : $$.getCurrentPaddingLeft()
}; };
// for subchart // for subchart
$$.margin2 = config.axis_rotated ? { $$.margin2 = config.axis_rotated ? {
top: $$.margin.top, top: $$.margin.top,
...@@ -401,7 +401,7 @@ ...@@ -401,7 +401,7 @@
bottom: xAxisHeight + legendHeightForBottom, bottom: xAxisHeight + legendHeightForBottom,
left: $$.margin.left left: $$.margin.left
}; };
// for legend // for legend
$$.margin3 = { $$.margin3 = {
top: 0, top: 0,
...@@ -410,17 +410,17 @@ ...@@ -410,17 +410,17 @@
left: 0 left: 0
}; };
if ($$.updateSizeForLegend) { $$.updateSizeForLegend(legendHeight, legendWidth); } if ($$.updateSizeForLegend) { $$.updateSizeForLegend(legendHeight, legendWidth); }
$$.width = $$.currentWidth - $$.margin.left - $$.margin.right; $$.width = $$.currentWidth - $$.margin.left - $$.margin.right;
$$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom;
if ($$.width < 0) { $$.width = 0; } if ($$.width < 0) { $$.width = 0; }
if ($$.height < 0) { $$.height = 0; } if ($$.height < 0) { $$.height = 0; }
$$.width2 = config.axis_rotated ? $$.margin.left - $$.rotated_padding_left - $$.rotated_padding_right : $$.width; $$.width2 = config.axis_rotated ? $$.margin.left - $$.rotated_padding_left - $$.rotated_padding_right : $$.width;
$$.height2 = config.axis_rotated ? $$.height : $$.currentHeight - $$.margin2.top - $$.margin2.bottom; $$.height2 = config.axis_rotated ? $$.height : $$.currentHeight - $$.margin2.top - $$.margin2.bottom;
if ($$.width2 < 0) { $$.width2 = 0; } if ($$.width2 < 0) { $$.width2 = 0; }
if ($$.height2 < 0) { $$.height2 = 0; } if ($$.height2 < 0) { $$.height2 = 0; }
// for arc // for arc
$$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0);
$$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10);
...@@ -428,33 +428,33 @@ ...@@ -428,33 +428,33 @@
$$.arcHeight += $$.height - $$.getGaugeLabelHeight(); $$.arcHeight += $$.height - $$.getGaugeLabelHeight();
} }
if ($$.updateRadius) { $$.updateRadius(); } if ($$.updateRadius) { $$.updateRadius(); }
if ($$.isLegendRight && hasArc) { if ($$.isLegendRight && hasArc) {
$$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1;
} }
}; };
c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.updateTargets = function (targets) {
var $$ = this; var $$ = this;
/*-- Main --*/ /*-- Main --*/
//-- Text --// //-- Text --//
$$.updateTargetsForText(targets); $$.updateTargetsForText(targets);
//-- Bar --// //-- Bar --//
$$.updateTargetsForBar(targets); $$.updateTargetsForBar(targets);
//-- Line --// //-- Line --//
$$.updateTargetsForLine(targets); $$.updateTargetsForLine(targets);
//-- Arc --// //-- Arc --//
if ($$.hasArcType() && $$.updateTargetsForArc) { $$.updateTargetsForArc(targets); } if ($$.hasArcType() && $$.updateTargetsForArc) { $$.updateTargetsForArc(targets); }
/*-- Sub --*/ /*-- Sub --*/
if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); } if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); }
// Fade-in each chart // Fade-in each chart
$$.showTargets(); $$.showTargets();
}; };
...@@ -464,7 +464,7 @@ ...@@ -464,7 +464,7 @@
.transition().duration($$.config.transition_duration) .transition().duration($$.config.transition_duration)
.style("opacity", 1); .style("opacity", 1);
}; };
c3_chart_internal_fn.redraw = function (options, transitions) { c3_chart_internal_fn.redraw = function (options, transitions) {
var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config;
var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType); var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType);
...@@ -477,7 +477,7 @@ ...@@ -477,7 +477,7 @@
var waitForDraw, flow; var waitForDraw, flow;
var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling, xDomainForZoom; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling, xDomainForZoom;
var xv = $$.xv.bind($$), cx, cy; var xv = $$.xv.bind($$), cx, cy;
options = options || {}; options = options || {};
withY = getOption(options, "withY", true); withY = getOption(options, "withY", true);
withSubchart = getOption(options, "withSubchart", true); withSubchart = getOption(options, "withSubchart", true);
...@@ -492,13 +492,13 @@ ...@@ -492,13 +492,13 @@
withDimension = getOption(options, "withDimension", true); withDimension = getOption(options, "withDimension", true);
withTransitionForExit = getOption(options, "withTransitionForExit", withTransition); withTransitionForExit = getOption(options, "withTransitionForExit", withTransition);
withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition); withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition);
duration = withTransition ? config.transition_duration : 0; duration = withTransition ? config.transition_duration : 0;
durationForExit = withTransitionForExit ? duration : 0; durationForExit = withTransitionForExit ? duration : 0;
durationForAxis = withTransitionForAxis ? duration : 0; durationForAxis = withTransitionForAxis ? duration : 0;
transitions = transitions || $$.axis.generateTransitions(durationForAxis); transitions = transitions || $$.axis.generateTransitions(durationForAxis);
// update legend and transform each g // update legend and transform each g
if (withLegend && config.legend_show) { if (withLegend && config.legend_show) {
$$.updateLegend($$.mapToIds($$.data.targets), options, transitions); $$.updateLegend($$.mapToIds($$.data.targets), options, transitions);
...@@ -507,12 +507,12 @@ ...@@ -507,12 +507,12 @@
// no need to update axis in it because they will be updated in redraw() // no need to update axis in it because they will be updated in redraw()
$$.updateDimension(true); $$.updateDimension(true);
} }
// MEMO: needed for grids calculation // MEMO: needed for grids calculation
if ($$.isCategorized() && targetsToShow.length === 0) { if ($$.isCategorized() && targetsToShow.length === 0) {
$$.x.domain([0, $$.axes.x.selectAll('.tick').size()]); $$.x.domain([0, $$.axes.x.selectAll('.tick').size()]);
} }
if (targetsToShow.length) { if (targetsToShow.length) {
$$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain); $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain);
if (!config.axis_x_tick_values) { if (!config.axis_x_tick_values) {
...@@ -522,27 +522,27 @@ ...@@ -522,27 +522,27 @@
$$.xAxis.tickValues([]); $$.xAxis.tickValues([]);
$$.subXAxis.tickValues([]); $$.subXAxis.tickValues([]);
} }
if (config.zoom_rescale && !options.flow) { if (config.zoom_rescale && !options.flow) {
xDomainForZoom = $$.x.orgDomain(); xDomainForZoom = $$.x.orgDomain();
} }
$$.y.domain($$.getYDomain(targetsToShow, 'y', xDomainForZoom)); $$.y.domain($$.getYDomain(targetsToShow, 'y', xDomainForZoom));
$$.y2.domain($$.getYDomain(targetsToShow, 'y2', xDomainForZoom)); $$.y2.domain($$.getYDomain(targetsToShow, 'y2', xDomainForZoom));
if (!config.axis_y_tick_values && config.axis_y_tick_count) { if (!config.axis_y_tick_values && config.axis_y_tick_count) {
$$.yAxis.tickValues($$.axis.generateTickValues($$.y.domain(), config.axis_y_tick_count)); $$.yAxis.tickValues($$.axis.generateTickValues($$.y.domain(), config.axis_y_tick_count));
} }
if (!config.axis_y2_tick_values && config.axis_y2_tick_count) { if (!config.axis_y2_tick_values && config.axis_y2_tick_count) {
$$.y2Axis.tickValues($$.axis.generateTickValues($$.y2.domain(), config.axis_y2_tick_count)); $$.y2Axis.tickValues($$.axis.generateTickValues($$.y2.domain(), config.axis_y2_tick_count));
} }
// axes // axes
$$.axis.redraw(transitions, hideAxis); $$.axis.redraw(transitions, hideAxis);
// Update axis label // Update axis label
$$.axis.updateLabels(withTransition); $$.axis.updateLabels(withTransition);
// show/hide if manual culling needed // show/hide if manual culling needed
if ((withUpdateXDomain || withUpdateXAxis) && targetsToShow.length) { if ((withUpdateXDomain || withUpdateXAxis) && targetsToShow.length) {
if (config.axis_x_tick_culling && tickValues) { if (config.axis_x_tick_culling && tickValues) {
...@@ -562,26 +562,26 @@ ...@@ -562,26 +562,26 @@
$$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block');
} }
} }
// setup drawer - MEMO: these must be called after axis updated // setup drawer - MEMO: these must be called after axis updated
drawArea = $$.generateDrawArea ? $$.generateDrawArea(areaIndices, false) : undefined; drawArea = $$.generateDrawArea ? $$.generateDrawArea(areaIndices, false) : undefined;
drawBar = $$.generateDrawBar ? $$.generateDrawBar(barIndices) : undefined; drawBar = $$.generateDrawBar ? $$.generateDrawBar(barIndices) : undefined;
drawLine = $$.generateDrawLine ? $$.generateDrawLine(lineIndices, false) : undefined; drawLine = $$.generateDrawLine ? $$.generateDrawLine(lineIndices, false) : undefined;
xForText = $$.generateXYForText(areaIndices, barIndices, lineIndices, true); xForText = $$.generateXYForText(areaIndices, barIndices, lineIndices, true);
yForText = $$.generateXYForText(areaIndices, barIndices, lineIndices, false); yForText = $$.generateXYForText(areaIndices, barIndices, lineIndices, false);
// Update sub domain // Update sub domain
if (withY) { if (withY) {
$$.subY.domain($$.getYDomain(targetsToShow, 'y')); $$.subY.domain($$.getYDomain(targetsToShow, 'y'));
$$.subY2.domain($$.getYDomain(targetsToShow, 'y2')); $$.subY2.domain($$.getYDomain(targetsToShow, 'y2'));
} }
// tooltip // tooltip
$$.tooltip.style("display", "none"); $$.tooltip.style("display", "none");
// xgrid focus // xgrid focus
$$.updateXgridFocus(); $$.updateXgridFocus();
// Data empty label positioning and text. // Data empty label positioning and text.
main.select("text." + CLASS.text + '.' + CLASS.empty) main.select("text." + CLASS.text + '.' + CLASS.empty)
.attr("x", $$.width / 2) .attr("x", $$.width / 2)
...@@ -589,56 +589,56 @@ ...@@ -589,56 +589,56 @@
.text(config.data_empty_label_text) .text(config.data_empty_label_text)
.transition() .transition()
.style('opacity', targetsToShow.length ? 0 : 1); .style('opacity', targetsToShow.length ? 0 : 1);
// grid // grid
$$.updateGrid(duration); $$.updateGrid(duration);
// rect for regions // rect for regions
$$.updateRegion(duration); $$.updateRegion(duration);
// bars // bars
$$.updateBar(durationForExit); $$.updateBar(durationForExit);
// lines, areas and cricles // lines, areas and cricles
$$.updateLine(durationForExit); $$.updateLine(durationForExit);
$$.updateArea(durationForExit); $$.updateArea(durationForExit);
$$.updateCircle(); $$.updateCircle();
// text // text
if ($$.hasDataLabel()) { if ($$.hasDataLabel()) {
$$.updateText(durationForExit); $$.updateText(durationForExit);
} }
// title // title
if ($$.redrawTitle) { $$.redrawTitle(); } if ($$.redrawTitle) { $$.redrawTitle(); }
// arc // arc
if ($$.redrawArc) { $$.redrawArc(duration, durationForExit, withTransform); } if ($$.redrawArc) { $$.redrawArc(duration, durationForExit, withTransform); }
// subchart // subchart
if ($$.redrawSubchart) { if ($$.redrawSubchart) {
$$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices);
} }
// circles for select // circles for select
main.selectAll('.' + CLASS.selectedCircles) main.selectAll('.' + CLASS.selectedCircles)
.filter($$.isBarType.bind($$)) .filter($$.isBarType.bind($$))
.selectAll('circle') .selectAll('circle')
.remove(); .remove();
// event rects will redrawn when flow called // event rects will redrawn when flow called
if (config.interaction_enabled && !options.flow && withEventRect) { if (config.interaction_enabled && !options.flow && withEventRect) {
$$.redrawEventRect(); $$.redrawEventRect();
if ($$.updateZoom) { $$.updateZoom(); } if ($$.updateZoom) { $$.updateZoom(); }
} }
// update circleY based on updated parameters // update circleY based on updated parameters
$$.updateCircleY(); $$.updateCircleY();
// generate circle x/y functions depending on updated params // generate circle x/y functions depending on updated params
cx = ($$.config.axis_rotated ? $$.circleY : $$.circleX).bind($$); cx = ($$.config.axis_rotated ? $$.circleY : $$.circleX).bind($$);
cy = ($$.config.axis_rotated ? $$.circleX : $$.circleY).bind($$); cy = ($$.config.axis_rotated ? $$.circleX : $$.circleY).bind($$);
if (options.flow) { if (options.flow) {
flow = $$.generateFlow({ flow = $$.generateFlow({
targets: targetsToShow, targets: targetsToShow,
...@@ -654,12 +654,12 @@ ...@@ -654,12 +654,12 @@
yForText: yForText yForText: yForText
}); });
} }
if ((duration || flow) && $$.isTabVisible()) { // Only use transition if tab visible. See #938. if ((duration || flow) && $$.isTabVisible()) { // Only use transition if tab visible. See #938.
// transition should be derived from one transition // transition should be derived from one transition
d3.transition().duration(duration).each(function () { d3.transition().duration(duration).each(function () {
var transitionsToWait = []; var transitionsToWait = [];
// redraw and gather transitions // redraw and gather transitions
[ [
$$.redrawBar(drawBar, true), $$.redrawBar(drawBar, true),
...@@ -674,7 +674,7 @@ ...@@ -674,7 +674,7 @@
transitionsToWait.push(transition); transitionsToWait.push(transition);
}); });
}); });
// Wait for end of transitions to call flow and onrendered callback // Wait for end of transitions to call flow and onrendered callback
waitForDraw = $$.generateWait(); waitForDraw = $$.generateWait();
transitionsToWait.forEach(function (t) { transitionsToWait.forEach(function (t) {
...@@ -702,13 +702,13 @@ ...@@ -702,13 +702,13 @@
config.onrendered.call($$); config.onrendered.call($$);
} }
} }
// update fadein condition // update fadein condition
$$.mapToIds($$.data.targets).forEach(function (id) { $$.mapToIds($$.data.targets).forEach(function (id) {
$$.withoutFadeIn[id] = true; $$.withoutFadeIn[id] = true;
}); });
}; };
c3_chart_internal_fn.updateAndRedraw = function (options) { c3_chart_internal_fn.updateAndRedraw = function (options) {
var $$ = this, config = $$.config, transitions; var $$ = this, config = $$.config, transitions;
options = options || {}; options = options || {};
...@@ -743,7 +743,7 @@ ...@@ -743,7 +743,7 @@
withTransitionForAxis: false withTransitionForAxis: false
}); });
}; };
c3_chart_internal_fn.isTimeSeries = function () { c3_chart_internal_fn.isTimeSeries = function () {
return this.config.axis_x_type === 'timeseries'; return this.config.axis_x_type === 'timeseries';
}; };
...@@ -754,11 +754,11 @@ ...@@ -754,11 +754,11 @@
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
return !$$.isTimeSeries() && (config.data_x || notEmpty(config.data_xs)); return !$$.isTimeSeries() && (config.data_x || notEmpty(config.data_xs));
}; };
c3_chart_internal_fn.isTimeSeriesY = function () { c3_chart_internal_fn.isTimeSeriesY = function () {
return this.config.axis_y_type === 'timeseries'; return this.config.axis_y_type === 'timeseries';
}; };
c3_chart_internal_fn.getTranslate = function (target) { c3_chart_internal_fn.getTranslate = function (target) {
var $$ = this, config = $$.config, x, y; var $$ = this, config = $$.config, x, y;
if (target === 'main') { if (target === 'main') {
...@@ -822,7 +822,7 @@ ...@@ -822,7 +822,7 @@
c3_chart_internal_fn.subxx = function (d) { c3_chart_internal_fn.subxx = function (d) {
return d ? this.subX(d.x) : null; return d ? this.subX(d.x) : null;
}; };
c3_chart_internal_fn.transformMain = function (withTransition, transitions) { c3_chart_internal_fn.transformMain = function (withTransition, transitions) {
var $$ = this, var $$ = this,
xAxis, yAxis, y2Axis; xAxis, yAxis, y2Axis;
...@@ -856,7 +856,7 @@ ...@@ -856,7 +856,7 @@
if ($$.config.subchart_show) { $$.transformContext(withTransition, transitions); } if ($$.config.subchart_show) { $$.transformContext(withTransition, transitions); }
if ($$.legend) { $$.transformLegend(withTransition); } if ($$.legend) { $$.transformLegend(withTransition); }
}; };
c3_chart_internal_fn.updateSvgSize = function () { c3_chart_internal_fn.updateSvgSize = function () {
var $$ = this, var $$ = this,
brush = $$.svg.select(".c3-brush .background"); brush = $$.svg.select(".c3-brush .background");
...@@ -883,8 +883,8 @@ ...@@ -883,8 +883,8 @@
// MEMO: parent div's height will be bigger than svg when <!DOCTYPE html> // MEMO: parent div's height will be bigger than svg when <!DOCTYPE html>
$$.selectChart.style('max-height', $$.currentHeight + "px"); $$.selectChart.style('max-height', $$.currentHeight + "px");
}; };
c3_chart_internal_fn.updateDimension = function (withoutAxis) { c3_chart_internal_fn.updateDimension = function (withoutAxis) {
var $$ = this; var $$ = this;
if (!withoutAxis) { if (!withoutAxis) {
...@@ -901,7 +901,7 @@ ...@@ -901,7 +901,7 @@
$$.updateSvgSize(); $$.updateSvgSize();
$$.transformAll(false); $$.transformAll(false);
}; };
c3_chart_internal_fn.observeInserted = function (selection) { c3_chart_internal_fn.observeInserted = function (selection) {
var $$ = this, observer; var $$ = this, observer;
if (typeof MutationObserver === 'undefined') { if (typeof MutationObserver === 'undefined') {
...@@ -936,8 +936,8 @@ ...@@ -936,8 +936,8 @@
}); });
observer.observe(selection.node(), {attributes: true, childList: true, characterData: true}); observer.observe(selection.node(), {attributes: true, childList: true, characterData: true});
}; };
c3_chart_internal_fn.generateResize = function () { c3_chart_internal_fn.generateResize = function () {
var resizeFunctions = []; var resizeFunctions = [];
function callResizeFunctions() { function callResizeFunctions() {
...@@ -950,7 +950,7 @@ ...@@ -950,7 +950,7 @@
}; };
return callResizeFunctions; return callResizeFunctions;
}; };
c3_chart_internal_fn.endall = function (transition, callback) { c3_chart_internal_fn.endall = function (transition, callback) {
var n = 0; var n = 0;
transition transition
...@@ -986,7 +986,7 @@ ...@@ -986,7 +986,7 @@
}; };
return f; return f;
}; };
c3_chart_internal_fn.parseDate = function (date) { c3_chart_internal_fn.parseDate = function (date) {
var $$ = this, parsedDate; var $$ = this, parsedDate;
if (date instanceof Date) { if (date instanceof Date) {
...@@ -1001,7 +1001,7 @@ ...@@ -1001,7 +1001,7 @@
} }
return parsedDate; return parsedDate;
}; };
c3_chart_internal_fn.isTabVisible = function () { c3_chart_internal_fn.isTabVisible = function () {
var hidden; var hidden;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
...@@ -1013,7 +1013,7 @@ ...@@ -1013,7 +1013,7 @@
} else if (typeof document.webkitHidden !== "undefined") { } else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden"; hidden = "webkitHidden";
} }
return document[hidden] ? false : true; return document[hidden] ? false : true;
}; };
...@@ -1211,6 +1211,8 @@ ...@@ -1211,6 +1211,8 @@
tooltip_init_show: false, tooltip_init_show: false,
tooltip_init_x: 0, tooltip_init_x: 0,
tooltip_init_position: {top: '0px', left: '50px'}, tooltip_init_position: {top: '0px', left: '50px'},
tooltip_onshow: function () {},
tooltip_onhide: function () {},
// title // title
title_text: undefined, title_text: undefined,
title_padding: { title_padding: {
...@@ -1332,12 +1334,12 @@ ...@@ -1332,12 +1334,12 @@
$$.xAxisTickValues = $$.axis.getXAxisTickValues(); $$.xAxisTickValues = $$.axis.getXAxisTickValues();
$$.yAxisTickValues = $$.axis.getYAxisTickValues(); $$.yAxisTickValues = $$.axis.getYAxisTickValues();
$$.y2AxisTickValues = $$.axis.getY2AxisTickValues(); $$.y2AxisTickValues = $$.axis.getY2AxisTickValues();
$$.xAxis = $$.axis.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); $$.xAxis = $$.axis.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer);
$$.subXAxis = $$.axis.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); $$.subXAxis = $$.axis.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer);
$$.yAxis = $$.axis.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, $$.yAxisTickValues, config.axis_y_tick_outer); $$.yAxis = $$.axis.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, $$.yAxisTickValues, config.axis_y_tick_outer);
$$.y2Axis = $$.axis.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, $$.y2AxisTickValues, config.axis_y2_tick_outer); $$.y2Axis = $$.axis.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, $$.y2AxisTickValues, config.axis_y2_tick_outer);
// Set initialized scales to brush and zoom // Set initialized scales to brush and zoom
if (!forInit) { if (!forInit) {
if ($$.brush) { $$.brush.scale($$.subX); } if ($$.brush) { $$.brush.scale($$.subX); }
...@@ -1424,11 +1426,11 @@ ...@@ -1424,11 +1426,11 @@
isInverted = axisId === 'y2' ? config.axis_y2_inverted : config.axis_y_inverted, isInverted = axisId === 'y2' ? config.axis_y2_inverted : config.axis_y_inverted,
showHorizontalDataLabel = $$.hasDataLabel() && config.axis_rotated, showHorizontalDataLabel = $$.hasDataLabel() && config.axis_rotated,
showVerticalDataLabel = $$.hasDataLabel() && !config.axis_rotated; showVerticalDataLabel = $$.hasDataLabel() && !config.axis_rotated;
// MEMO: avoid inverting domain unexpectedly // MEMO: avoid inverting domain unexpectedly
yDomainMin = isValue(yMin) ? yMin : isValue(yMax) ? (yDomainMin < yMax ? yDomainMin : yMax - 10) : yDomainMin; yDomainMin = isValue(yMin) ? yMin : isValue(yMax) ? (yDomainMin < yMax ? yDomainMin : yMax - 10) : yDomainMin;
yDomainMax = isValue(yMax) ? yMax : isValue(yMin) ? (yMin < yDomainMax ? yDomainMax : yMin + 10) : yDomainMax; yDomainMax = isValue(yMax) ? yMax : isValue(yMin) ? (yMin < yDomainMax ? yDomainMax : yMin + 10) : yDomainMax;
if (yTargets.length === 0) { // use current domain if target of axisId is none if (yTargets.length === 0) { // use current domain if target of axisId is none
return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); return axisId === 'y2' ? $$.y2.domain() : $$.y.domain();
} }
...@@ -1443,21 +1445,21 @@ ...@@ -1443,21 +1445,21 @@
} }
isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; isAllPositive = yDomainMin >= 0 && yDomainMax >= 0;
isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; isAllNegative = yDomainMin <= 0 && yDomainMax <= 0;
// Cancel zerobased if axis_*_min / axis_*_max specified // Cancel zerobased if axis_*_min / axis_*_max specified
if ((isValue(yMin) && isAllPositive) || (isValue(yMax) && isAllNegative)) { if ((isValue(yMin) && isAllPositive) || (isValue(yMax) && isAllNegative)) {
isZeroBased = false; isZeroBased = false;
} }
// Bar/Area chart should be 0-based if all positive|negative // Bar/Area chart should be 0-based if all positive|negative
if (isZeroBased) { if (isZeroBased) {
if (isAllPositive) { yDomainMin = 0; } if (isAllPositive) { yDomainMin = 0; }
if (isAllNegative) { yDomainMax = 0; } if (isAllNegative) { yDomainMax = 0; }
} }
domainLength = Math.abs(yDomainMax - yDomainMin); domainLength = Math.abs(yDomainMax - yDomainMin);
padding = padding_top = padding_bottom = domainLength * 0.1; padding = padding_top = padding_bottom = domainLength * 0.1;
if (typeof center !== 'undefined') { if (typeof center !== 'undefined') {
yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax));
yDomainMax = center + yDomainAbs; yDomainMax = center + yDomainAbs;
...@@ -1551,7 +1553,7 @@ ...@@ -1551,7 +1553,7 @@
}; };
c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, withTrim, domain) { c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, withTrim, domain) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
if (withUpdateOrgXDomain) { if (withUpdateOrgXDomain) {
$$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets)));
$$.orgXDomain = $$.x.domain(); $$.orgXDomain = $$.x.domain();
...@@ -1563,10 +1565,10 @@ ...@@ -1563,10 +1565,10 @@
$$.x.domain(domain ? domain : (!$$.brush || $$.brush.empty()) ? $$.orgXDomain : $$.brush.extent()); $$.x.domain(domain ? domain : (!$$.brush || $$.brush.empty()) ? $$.orgXDomain : $$.brush.extent());
if (config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } if (config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); }
} }
// Trim domain when too big by zoom mousemove event // Trim domain when too big by zoom mousemove event
if (withTrim) { $$.x.domain($$.trimXDomain($$.x.orgDomain())); } if (withTrim) { $$.x.domain($$.trimXDomain($$.x.orgDomain())); }
return $$.x.domain(); return $$.x.domain();
}; };
c3_chart_internal_fn.trimXDomain = function (domain) { c3_chart_internal_fn.trimXDomain = function (domain) {
...@@ -1876,21 +1878,21 @@ ...@@ -1876,21 +1878,21 @@
} }
return sames; return sames;
}; };
c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) {
var $$ = this, candidates; var $$ = this, candidates;
// map to array of closest points of each target // map to array of closest points of each target
candidates = targets.map(function (target) { candidates = targets.map(function (target) {
return $$.findClosest(target.values, pos); return $$.findClosest(target.values, pos);
}); });
// decide closest point and return // decide closest point and return
return $$.findClosest(candidates, pos); return $$.findClosest(candidates, pos);
}; };
c3_chart_internal_fn.findClosest = function (values, pos) { c3_chart_internal_fn.findClosest = function (values, pos) {
var $$ = this, minDist = 100, closest; var $$ = this, minDist = 100, closest;
// find mouseovering bar // find mouseovering bar
values.filter(function (v) { return v && $$.isBarType(v.id); }).forEach(function (v) { values.filter(function (v) { return v && $$.isBarType(v.id); }).forEach(function (v) {
var shape = $$.main.select('.' + CLASS.bars + $$.getTargetSelectorSuffix(v.id) + ' .' + CLASS.bar + '-' + v.index).node(); var shape = $$.main.select('.' + CLASS.bars + $$.getTargetSelectorSuffix(v.id) + ' .' + CLASS.bar + '-' + v.index).node();
...@@ -1898,7 +1900,7 @@ ...@@ -1898,7 +1900,7 @@
closest = v; closest = v;
} }
}); });
// find closest point from non-bar // find closest point from non-bar
values.filter(function (v) { return v && !$$.isBarType(v.id); }).forEach(function (v) { values.filter(function (v) { return v && !$$.isBarType(v.id); }).forEach(function (v) {
var d = $$.dist(v, pos); var d = $$.dist(v, pos);
...@@ -1907,7 +1909,7 @@ ...@@ -1907,7 +1909,7 @@
closest = v; closest = v;
} }
}); });
return closest; return closest;
}; };
c3_chart_internal_fn.dist = function (data, pos) { c3_chart_internal_fn.dist = function (data, pos) {
...@@ -1920,15 +1922,15 @@ ...@@ -1920,15 +1922,15 @@
}; };
c3_chart_internal_fn.convertValuesToStep = function (values) { c3_chart_internal_fn.convertValuesToStep = function (values) {
var converted = [].concat(values), i; var converted = [].concat(values), i;
if (!this.isCategorized()) { if (!this.isCategorized()) {
return values; return values;
} }
for (i = values.length + 1; 0 < i; i--) { for (i = values.length + 1; 0 < i; i--) {
converted[i] = converted[i - 1]; converted[i] = converted[i - 1];
} }
converted[0] = { converted[0] = {
x: converted[0].x - 1, x: converted[0].x - 1,
value: converted[0].value, value: converted[0].value,
...@@ -1939,7 +1941,7 @@ ...@@ -1939,7 +1941,7 @@
value: converted[values.length].value, value: converted[values.length].value,
id: converted[values.length].id id: converted[values.length].id
}; };
return converted; return converted;
}; };
c3_chart_internal_fn.updateDataAttributes = function (name, attrs) { c3_chart_internal_fn.updateDataAttributes = function (name, attrs) {
...@@ -2051,11 +2053,11 @@ ...@@ -2051,11 +2053,11 @@
ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), ids = $$.d3.keys(data[0]).filter($$.isNotX, $$),
xs = $$.d3.keys(data[0]).filter($$.isX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$),
targets; targets;
// save x for update data by load when custom x and c3.x API // save x for update data by load when custom x and c3.x API
ids.forEach(function (id) { ids.forEach(function (id) {
var xKey = $$.getXKey(id); var xKey = $$.getXKey(id);
if ($$.isCustomX() || $$.isTimeSeries()) { if ($$.isCustomX() || $$.isTimeSeries()) {
// if included in input data // if included in input data
if (xs.indexOf(xKey) >= 0) { if (xs.indexOf(xKey) >= 0) {
...@@ -2078,15 +2080,15 @@ ...@@ -2078,15 +2080,15 @@
$$.data.xs[id] = data.map(function (d, i) { return i; }); $$.data.xs[id] = data.map(function (d, i) { return i; });
} }
}); });
// check x is defined // check x is defined
ids.forEach(function (id) { ids.forEach(function (id) {
if (!$$.data.xs[id]) { if (!$$.data.xs[id]) {
throw new Error('x is not defined for id = "' + id + '".'); throw new Error('x is not defined for id = "' + id + '".');
} }
}); });
// convert to target // convert to target
targets = ids.map(function (id, index) { targets = ids.map(function (id, index) {
var convertedId = config.data_idConverter(id); var convertedId = config.data_idConverter(id);
...@@ -2108,7 +2110,7 @@ ...@@ -2108,7 +2110,7 @@
}).filter(function (v) { return isDefined(v.x); }) }).filter(function (v) { return isDefined(v.x); })
}; };
}); });
// finish targets // finish targets
targets.forEach(function (t) { targets.forEach(function (t) {
var i; var i;
...@@ -2130,17 +2132,17 @@ ...@@ -2130,17 +2132,17 @@
return v1 - v2; return v1 - v2;
}); });
}); });
// set target types // set target types
if (config.data_type) { if (config.data_type) {
$$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in config.data_types); }), config.data_type); $$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in config.data_types); }), config.data_type);
} }
// cache as original id keyed // cache as original id keyed
targets.forEach(function (d) { targets.forEach(function (d) {
$$.addCache(d.id_org, d); $$.addCache(d.id_org, d);
}); });
return targets; return targets;
}; };
...@@ -2170,13 +2172,13 @@ ...@@ -2170,13 +2172,13 @@
}); });
$$.data.targets = $$.data.targets.concat(targets); // add remained $$.data.targets = $$.data.targets.concat(targets); // add remained
} }
// Set targets // Set targets
$$.updateTargets($$.data.targets); $$.updateTargets($$.data.targets);
// Redraw with new targets // Redraw with new targets
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
if (args.done) { args.done(); } if (args.done) { args.done(); }
}; };
c3_chart_internal_fn.loadFromArgs = function (args) { c3_chart_internal_fn.loadFromArgs = function (args) {
...@@ -2248,19 +2250,19 @@ ...@@ -2248,19 +2250,19 @@
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
eventRectUpdate, maxDataCountTarget, eventRectUpdate, maxDataCountTarget,
isMultipleX = $$.isMultipleX(); isMultipleX = $$.isMultipleX();
// rects for mouseover // rects for mouseover
var eventRects = $$.main.select('.' + CLASS.eventRects) var eventRects = $$.main.select('.' + CLASS.eventRects)
.style('cursor', config.zoom_enabled ? config.axis_rotated ? 'ns-resize' : 'ew-resize' : null) .style('cursor', config.zoom_enabled ? config.axis_rotated ? 'ns-resize' : 'ew-resize' : null)
.classed(CLASS.eventRectsMultiple, isMultipleX) .classed(CLASS.eventRectsMultiple, isMultipleX)
.classed(CLASS.eventRectsSingle, !isMultipleX); .classed(CLASS.eventRectsSingle, !isMultipleX);
// clear old rects // clear old rects
eventRects.selectAll('.' + CLASS.eventRect).remove(); eventRects.selectAll('.' + CLASS.eventRect).remove();
// open as public variable // open as public variable
$$.eventRect = eventRects.selectAll('.' + CLASS.eventRect); $$.eventRect = eventRects.selectAll('.' + CLASS.eventRect);
if (isMultipleX) { if (isMultipleX) {
eventRectUpdate = $$.eventRect.data([0]); eventRectUpdate = $$.eventRect.data([0]);
// enter : only one rect will be added // enter : only one rect will be added
...@@ -2286,10 +2288,10 @@ ...@@ -2286,10 +2288,10 @@
c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) { c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
x, y, w, h, rectW, rectX; x, y, w, h, rectW, rectX;
// set update selection if null // set update selection if null
eventRectUpdate = eventRectUpdate || $$.eventRect.data(function (d) { return d; }); eventRectUpdate = eventRectUpdate || $$.eventRect.data(function (d) { return d; });
if ($$.isMultipleX()) { if ($$.isMultipleX()) {
// TODO: rotated not supported yet // TODO: rotated not supported yet
x = 0; x = 0;
...@@ -2299,34 +2301,34 @@ ...@@ -2299,34 +2301,34 @@
} }
else { else {
if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) {
// update index for x that is used by prevX and nextX // update index for x that is used by prevX and nextX
$$.updateXs(); $$.updateXs();
rectW = function (d) { rectW = function (d) {
var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index); var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index);
// if there this is a single data point make the eventRect full width (or height) // if there this is a single data point make the eventRect full width (or height)
if (prevX === null && nextX === null) { if (prevX === null && nextX === null) {
return config.axis_rotated ? $$.height : $$.width; return config.axis_rotated ? $$.height : $$.width;
} }
if (prevX === null) { prevX = $$.x.domain()[0]; } if (prevX === null) { prevX = $$.x.domain()[0]; }
if (nextX === null) { nextX = $$.x.domain()[1]; } if (nextX === null) { nextX = $$.x.domain()[1]; }
return Math.max(0, ($$.x(nextX) - $$.x(prevX)) / 2); return Math.max(0, ($$.x(nextX) - $$.x(prevX)) / 2);
}; };
rectX = function (d) { rectX = function (d) {
var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index),
thisX = $$.data.xs[d.id][d.index]; thisX = $$.data.xs[d.id][d.index];
// if there this is a single data point position the eventRect at 0 // if there this is a single data point position the eventRect at 0
if (prevX === null && nextX === null) { if (prevX === null && nextX === null) {
return 0; return 0;
} }
if (prevX === null) { prevX = $$.x.domain()[0]; } if (prevX === null) { prevX = $$.x.domain()[0]; }
return ($$.x(thisX) + $$.x(prevX)) / 2; return ($$.x(thisX) + $$.x(prevX)) / 2;
}; };
} else { } else {
...@@ -2340,7 +2342,7 @@ ...@@ -2340,7 +2342,7 @@
w = config.axis_rotated ? $$.width : rectW; w = config.axis_rotated ? $$.width : rectW;
h = config.axis_rotated ? rectW : $$.height; h = config.axis_rotated ? rectW : $$.height;
} }
eventRectUpdate eventRectUpdate
.attr('class', $$.classEvent.bind($$)) .attr('class', $$.classEvent.bind($$))
.attr("x", x) .attr("x", x)
...@@ -2355,14 +2357,14 @@ ...@@ -2355,14 +2357,14 @@
.style("cursor", config.data_selection_enabled && config.data_selection_grouped ? "pointer" : null) .style("cursor", config.data_selection_enabled && config.data_selection_grouped ? "pointer" : null)
.on('mouseover', function (d) { .on('mouseover', function (d) {
var index = d.index; var index = d.index;
if ($$.dragging || $$.flowing) { return; } // do nothing while dragging/flowing if ($$.dragging || $$.flowing) { return; } // do nothing while dragging/flowing
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
// Expand shapes for selection // Expand shapes for selection
if (config.point_focus_expand_enabled) { $$.expandCircles(index, null, true); } if (config.point_focus_expand_enabled) { $$.expandCircles(index, null, true); }
$$.expandBars(index, null, true); $$.expandBars(index, null, true);
// Call event handler // Call event handler
$$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) {
config.data_onmouseover.call($$.api, d); config.data_onmouseover.call($$.api, d);
...@@ -2385,28 +2387,28 @@ ...@@ -2385,28 +2387,28 @@
.on('mousemove', function (d) { .on('mousemove', function (d) {
var selectedData, index = d.index, var selectedData, index = d.index,
eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index);
if ($$.dragging || $$.flowing) { return; } // do nothing while dragging/flowing if ($$.dragging || $$.flowing) { return; } // do nothing while dragging/flowing
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
if ($$.isStepType(d) && $$.config.line_step_type === 'step-after' && d3.mouse(this)[0] < $$.x($$.getXValue(d.id, index))) { if ($$.isStepType(d) && $$.config.line_step_type === 'step-after' && d3.mouse(this)[0] < $$.x($$.getXValue(d.id, index))) {
index -= 1; index -= 1;
} }
// Show tooltip // Show tooltip
selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) {
return $$.addName($$.getValueOnIndex(t.values, index)); return $$.addName($$.getValueOnIndex(t.values, index));
}); });
if (config.tooltip_grouped) { if (config.tooltip_grouped) {
$$.showTooltip(selectedData, this); $$.showTooltip(selectedData, this);
$$.showXGridFocus(selectedData); $$.showXGridFocus(selectedData);
} }
if (config.tooltip_grouped && (!config.data_selection_enabled || config.data_selection_grouped)) { if (config.tooltip_grouped && (!config.data_selection_enabled || config.data_selection_grouped)) {
return; return;
} }
$$.main.selectAll('.' + CLASS.shape + '-' + index) $$.main.selectAll('.' + CLASS.shape + '-' + index)
.each(function () { .each(function () {
d3.select(this).classed(CLASS.EXPANDED, true); d3.select(this).classed(CLASS.EXPANDED, true);
...@@ -2463,10 +2465,10 @@ ...@@ -2463,10 +2465,10 @@
) : function () {} ) : function () {}
); );
}; };
c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) {
var $$ = this, d3 = $$.d3, config = $$.config; var $$ = this, d3 = $$.d3, config = $$.config;
function mouseout() { function mouseout() {
$$.svg.select('.' + CLASS.eventRect).style('cursor', null); $$.svg.select('.' + CLASS.eventRect).style('cursor', null);
$$.hideXGridFocus(); $$.hideXGridFocus();
...@@ -2474,7 +2476,7 @@ ...@@ -2474,7 +2476,7 @@
$$.unexpandCircles(); $$.unexpandCircles();
$$.unexpandBars(); $$.unexpandBars();
} }
eventRectEnter.append('rect') eventRectEnter.append('rect')
.attr('x', 0) .attr('x', 0)
.attr('y', 0) .attr('y', 0)
...@@ -2489,44 +2491,44 @@ ...@@ -2489,44 +2491,44 @@
.on('mousemove', function () { .on('mousemove', function () {
var targetsToShow = $$.filterTargetsToShow($$.data.targets); var targetsToShow = $$.filterTargetsToShow($$.data.targets);
var mouse, closest, sameXData, selectedData; var mouse, closest, sameXData, selectedData;
if ($$.dragging) { return; } // do nothing when dragging if ($$.dragging) { return; } // do nothing when dragging
if ($$.hasArcType(targetsToShow)) { return; } if ($$.hasArcType(targetsToShow)) { return; }
mouse = d3.mouse(this); mouse = d3.mouse(this);
closest = $$.findClosestFromTargets(targetsToShow, mouse); closest = $$.findClosestFromTargets(targetsToShow, mouse);
if ($$.mouseover && (!closest || closest.id !== $$.mouseover.id)) { if ($$.mouseover && (!closest || closest.id !== $$.mouseover.id)) {
config.data_onmouseout.call($$.api, $$.mouseover); config.data_onmouseout.call($$.api, $$.mouseover);
$$.mouseover = undefined; $$.mouseover = undefined;
} }
if (! closest) { if (! closest) {
mouseout(); mouseout();
return; return;
} }
if ($$.isScatterType(closest) || !config.tooltip_grouped) { if ($$.isScatterType(closest) || !config.tooltip_grouped) {
sameXData = [closest]; sameXData = [closest];
} else { } else {
sameXData = $$.filterByX(targetsToShow, closest.x); sameXData = $$.filterByX(targetsToShow, closest.x);
} }
// show tooltip when cursor is close to some point // show tooltip when cursor is close to some point
selectedData = sameXData.map(function (d) { selectedData = sameXData.map(function (d) {
return $$.addName(d); return $$.addName(d);
}); });
$$.showTooltip(selectedData, this); $$.showTooltip(selectedData, this);
// expand points // expand points
if (config.point_focus_expand_enabled) { if (config.point_focus_expand_enabled) {
$$.expandCircles(closest.index, closest.id, true); $$.expandCircles(closest.index, closest.id, true);
} }
$$.expandBars(closest.index, closest.id, true); $$.expandBars(closest.index, closest.id, true);
// Show xgrid focus line // Show xgrid focus line
$$.showXGridFocus(selectedData); $$.showXGridFocus(selectedData);
// Show cursor as pointer if point is close to mouse position // Show cursor as pointer if point is close to mouse position
if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < 100) { if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < 100) {
$$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer');
...@@ -2539,14 +2541,14 @@ ...@@ -2539,14 +2541,14 @@
.on('click', function () { .on('click', function () {
var targetsToShow = $$.filterTargetsToShow($$.data.targets); var targetsToShow = $$.filterTargetsToShow($$.data.targets);
var mouse, closest; var mouse, closest;
if ($$.hasArcType(targetsToShow)) { return; } if ($$.hasArcType(targetsToShow)) { return; }
mouse = d3.mouse(this); mouse = d3.mouse(this);
closest = $$.findClosestFromTargets(targetsToShow, mouse); closest = $$.findClosestFromTargets(targetsToShow, mouse);
if (! closest) { return; } if (! closest) { return; }
// select if selection enabled // select if selection enabled
if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < 100) { if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < 100) {
$$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(closest.id)).selectAll('.' + CLASS.shape + '-' + closest.index).each(function () { $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(closest.id)).selectAll('.' + CLASS.shape + '-' + closest.index).each(function () {
...@@ -2574,7 +2576,7 @@ ...@@ -2574,7 +2576,7 @@
x = box.left + (mouse ? mouse[0] : 0), x = box.left + (mouse ? mouse[0] : 0),
y = box.top + (mouse ? mouse[1] : 0), y = box.top + (mouse ? mouse[1] : 0),
event = document.createEvent("MouseEvents"); event = document.createEvent("MouseEvents");
event.initMouseEvent(type, true, true, window, 0, x, y, x, y, event.initMouseEvent(type, true, true, window, 0, x, y, x, y,
false, false, false, false, 0, null); false, false, false, false, 0, null);
eventRect.dispatchEvent(event); eventRect.dispatchEvent(event);
...@@ -2627,7 +2629,7 @@ ...@@ -2627,7 +2629,7 @@
return ceil10($$.getAxisWidthByAxisId('y2')) + legendWidthOnRight; return ceil10($$.getAxisWidthByAxisId('y2')) + legendWidthOnRight;
} }
}; };
c3_chart_internal_fn.getParentRectValue = function (key) { c3_chart_internal_fn.getParentRectValue = function (key) {
var parent = this.selectChart.node(), v; var parent = this.selectChart.node(), v;
while (parent && parent.tagName !== 'BODY') { while (parent && parent.tagName !== 'BODY') {
...@@ -2654,8 +2656,8 @@ ...@@ -2654,8 +2656,8 @@
var h = this.selectChart.style('height'); var h = this.selectChart.style('height');
return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; return h.indexOf('px') > 0 ? +h.replace('px', '') : 0;
}; };
c3_chart_internal_fn.getSvgLeft = function (withoutRecompute) { c3_chart_internal_fn.getSvgLeft = function (withoutRecompute) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
hasLeftAxisRect = config.axis_rotated || (!config.axis_rotated && !config.axis_y_inner), hasLeftAxisRect = config.axis_rotated || (!config.axis_rotated && !config.axis_y_inner),
...@@ -2667,8 +2669,8 @@ ...@@ -2667,8 +2669,8 @@
svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft(withoutRecompute)); svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft(withoutRecompute));
return svgLeft > 0 ? svgLeft : 0; return svgLeft > 0 ? svgLeft : 0;
}; };
c3_chart_internal_fn.getAxisWidthByAxisId = function (id, withoutRecompute) { c3_chart_internal_fn.getAxisWidthByAxisId = function (id, withoutRecompute) {
var $$ = this, position = $$.axis.getLabelPositionById(id); var $$ = this, position = $$.axis.getLabelPositionById(id);
return $$.axis.getMaxTickWidth(id, withoutRecompute) + (position.isInner ? 20 : 40); return $$.axis.getMaxTickWidth(id, withoutRecompute) + (position.isInner ? 20 : 40);
...@@ -2685,7 +2687,7 @@ ...@@ -2685,7 +2687,7 @@
} }
return h + ($$.axis.getLabelPositionById(axisId).isInner ? 0 : 10) + (axisId === 'y2' ? -10 : 0); return h + ($$.axis.getLabelPositionById(axisId).isInner ? 0 : 10) + (axisId === 'y2' ? -10 : 0);
}; };
c3_chart_internal_fn.getEventRectWidth = function () { c3_chart_internal_fn.getEventRectWidth = function () {
return Math.max(0, this.xAxis.tickInterval()); return Math.max(0, this.xAxis.tickInterval());
}; };
...@@ -2755,8 +2757,8 @@ ...@@ -2755,8 +2757,8 @@
} }
return isWithin; return isWithin;
}; };
c3_chart_internal_fn.getInterpolate = function (d) { c3_chart_internal_fn.getInterpolate = function (d) {
var $$ = this; var $$ = this;
return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? $$.config.line_step_type : "linear"; return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? $$.config.line_step_type : "linear";
...@@ -2835,7 +2837,7 @@ ...@@ -2835,7 +2837,7 @@
yValue = function (d, i) { yValue = function (d, i) {
return config.data_groups.length > 0 ? getPoints(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); return config.data_groups.length > 0 ? getPoints(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value);
}; };
line = config.axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); line = config.axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue);
if (!config.line_connectNull) { line = line.defined(function (d) { return d.value != null; }); } if (!config.line_connectNull) { line = line.defined(function (d) { return d.value != null; }); }
return function (d) { return function (d) {
...@@ -2882,8 +2884,8 @@ ...@@ -2882,8 +2884,8 @@
]; ];
}; };
}; };
c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
prev = -1, i, j, prev = -1, i, j,
...@@ -2892,7 +2894,7 @@ ...@@ -2892,7 +2894,7 @@
xOffset = $$.isCategorized() ? 0.5 : 0, xOffset = $$.isCategorized() ? 0.5 : 0,
xValue, yValue, xValue, yValue,
regions = []; regions = [];
function isWithinRegions(x, regions) { function isWithinRegions(x, regions) {
var i; var i;
for (i = 0; i < regions.length; i++) { for (i = 0; i < regions.length; i++) {
...@@ -2900,7 +2902,7 @@ ...@@ -2900,7 +2902,7 @@
} }
return false; return false;
} }
// Check start/end of regions // Check start/end of regions
if (isDefined(_regions)) { if (isDefined(_regions)) {
for (i = 0; i < _regions.length; i++) { for (i = 0; i < _regions.length; i++) {
...@@ -2917,11 +2919,11 @@ ...@@ -2917,11 +2919,11 @@
} }
} }
} }
// Set scales // Set scales
xValue = config.axis_rotated ? function (d) { return y(d.value); } : function (d) { return x(d.x); }; xValue = config.axis_rotated ? function (d) { return y(d.value); } : function (d) { return x(d.x); };
yValue = config.axis_rotated ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; yValue = config.axis_rotated ? function (d) { return x(d.x); } : function (d) { return y(d.value); };
// Define svg generator function for region // Define svg generator function for region
function generateM(points) { function generateM(points) {
return 'M' + points[0][0] + ' ' + points[0][1] + ' ' + points[1][0] + ' ' + points[1][1]; return 'M' + points[0][0] + ' ' + points[0][1] + ' ' + points[1][0] + ' ' + points[1][1];
...@@ -2950,10 +2952,10 @@ ...@@ -2950,10 +2952,10 @@
return generateM(points); return generateM(points);
}; };
} }
// Generate // Generate
for (i = 0; i < d.length; i++) { for (i = 0; i < d.length; i++) {
// Draw as normal // Draw as normal
if (isUndefined(regions) || ! isWithinRegions(d[i].x, regions)) { if (isUndefined(regions) || ! isWithinRegions(d[i].x, regions)) {
s += " " + xValue(d[i]) + " " + yValue(d[i]); s += " " + xValue(d[i]) + " " + yValue(d[i]);
...@@ -2962,24 +2964,24 @@ ...@@ -2962,24 +2964,24 @@
else { else {
xp = $$.getScale(d[i - 1].x + xOffset, d[i].x + xOffset, $$.isTimeSeries()); xp = $$.getScale(d[i - 1].x + xOffset, d[i].x + xOffset, $$.isTimeSeries());
yp = $$.getScale(d[i - 1].value, d[i].value); yp = $$.getScale(d[i - 1].value, d[i].value);
dx = x(d[i].x) - x(d[i - 1].x); dx = x(d[i].x) - x(d[i - 1].x);
dy = y(d[i].value) - y(d[i - 1].value); dy = y(d[i].value) - y(d[i - 1].value);
dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
diff = 2 / dd; diff = 2 / dd;
diffx2 = diff * 2; diffx2 = diff * 2;
for (j = diff; j <= 1; j += diffx2) { for (j = diff; j <= 1; j += diffx2) {
s += sWithRegion(d[i - 1], d[i], j, diff); s += sWithRegion(d[i - 1], d[i], j, diff);
} }
} }
prev = d[i].x; prev = d[i].x;
} }
return s; return s;
}; };
c3_chart_internal_fn.updateArea = function (durationForExit) { c3_chart_internal_fn.updateArea = function (durationForExit) {
var $$ = this, d3 = $$.d3; var $$ = this, d3 = $$.d3;
$$.mainArea = $$.main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) $$.mainArea = $$.main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area)
...@@ -3013,12 +3015,12 @@ ...@@ -3013,12 +3015,12 @@
value1 = function (d, i) { value1 = function (d, i) {
return config.data_groups.length > 0 ? getPoints(d, i)[1][1] : yScaleGetter.call($$, d.id)(d.value); return config.data_groups.length > 0 ? getPoints(d, i)[1][1] : yScaleGetter.call($$, d.id)(d.value);
}; };
area = config.axis_rotated ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1); area = config.axis_rotated ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1);
if (!config.line_connectNull) { if (!config.line_connectNull) {
area = area.defined(function (d) { return d.value !== null; }); area = area.defined(function (d) { return d.value !== null; });
} }
return function (d) { return function (d) {
var values = config.line_connectNull ? $$.filterRemoveNull(d.values) : d.values, var values = config.line_connectNull ? $$.filterRemoveNull(d.values) : d.values,
x0 = 0, y0 = 0, path; x0 = 0, y0 = 0, path;
...@@ -3062,8 +3064,8 @@ ...@@ -3062,8 +3064,8 @@
]; ];
}; };
}; };
c3_chart_internal_fn.updateCircle = function () { c3_chart_internal_fn.updateCircle = function () {
var $$ = this; var $$ = this;
$$.mainCircle = $$.main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) $$.mainCircle = $$.main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle)
...@@ -3170,7 +3172,7 @@ ...@@ -3170,7 +3172,7 @@
mainBarEnter.append('g') mainBarEnter.append('g')
.attr("class", classBars) .attr("class", classBars)
.style("cursor", function (d) { return config.data_selection_isselectable(d) ? "pointer" : null; }); .style("cursor", function (d) { return config.data_selection_isselectable(d) ? "pointer" : null; });
}; };
c3_chart_internal_fn.updateBar = function (durationForExit) { c3_chart_internal_fn.updateBar = function (durationForExit) {
var $$ = this, var $$ = this,
...@@ -3222,17 +3224,17 @@ ...@@ -3222,17 +3224,17 @@
return function (d, i) { return function (d, i) {
// 4 points that make a bar // 4 points that make a bar
var points = getPoints(d, i); var points = getPoints(d, i);
// switch points if axis is rotated, not applicable for sub chart // switch points if axis is rotated, not applicable for sub chart
var indexX = config.axis_rotated ? 1 : 0; var indexX = config.axis_rotated ? 1 : 0;
var indexY = config.axis_rotated ? 0 : 1; var indexY = config.axis_rotated ? 0 : 1;
var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' +
'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' +
'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' +
'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' +
'z'; 'z';
return path; return path;
}; };
}; };
...@@ -3519,7 +3521,7 @@ ...@@ -3519,7 +3521,7 @@
var $$ = this, config = $$.config, d3 = $$.d3, var $$ = this, config = $$.config, d3 = $$.d3,
xgridData = $$.generateGridData(config.grid_x_type, $$.x), xgridData = $$.generateGridData(config.grid_x_type, $$.x),
tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0;
$$.xgridAttr = config.axis_rotated ? { $$.xgridAttr = config.axis_rotated ? {
'x1': 0, 'x1': 0,
'x2': $$.width, 'x2': $$.width,
...@@ -3531,7 +3533,7 @@ ...@@ -3531,7 +3533,7 @@
'y1': 0, 'y1': 0,
'y2': $$.height 'y2': $$.height
}; };
$$.xgrid = $$.main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) $$.xgrid = $$.main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid)
.data(xgridData); .data(xgridData);
$$.xgrid.enter().append('line').attr("class", CLASS.xgrid); $$.xgrid.enter().append('line').attr("class", CLASS.xgrid);
...@@ -3541,7 +3543,7 @@ ...@@ -3541,7 +3543,7 @@
} }
$$.xgrid.exit().remove(); $$.xgrid.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);
...@@ -3556,7 +3558,7 @@ ...@@ -3556,7 +3558,7 @@
$$.ygrid.exit().remove(); $$.ygrid.exit().remove();
$$.smoothLines($$.ygrid, 'grid'); $$.smoothLines($$.ygrid, 'grid');
}; };
c3_chart_internal_fn.gridTextAnchor = function (d) { c3_chart_internal_fn.gridTextAnchor = function (d) {
return d.position ? d.position : "end"; return d.position ? d.position : "end";
}; };
...@@ -3572,10 +3574,10 @@ ...@@ -3572,10 +3574,10 @@
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, ygridLine, yv;
// hide if arc type // hide if arc type
$$.grid.style('visibility', $$.hasArcType() ? 'hidden' : 'visible'); $$.grid.style('visibility', $$.hasArcType() ? 'hidden' : 'visible');
main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden");
if (config.grid_x_show) { if (config.grid_x_show) {
$$.updateXGrid(); $$.updateXGrid();
...@@ -3599,7 +3601,7 @@ ...@@ -3599,7 +3601,7 @@
$$.xgridLines.exit().transition().duration(duration) $$.xgridLines.exit().transition().duration(duration)
.style("opacity", 0) .style("opacity", 0)
.remove(); .remove();
// Y-Grid // Y-Grid
if (config.grid_y_show) { if (config.grid_y_show) {
$$.updateYGrid(); $$.updateYGrid();
...@@ -3761,17 +3763,17 @@ ...@@ -3761,17 +3763,17 @@
text, i, title, value, name, bgcolor; text, i, title, value, name, bgcolor;
for (i = 0; i < d.length; i++) { for (i = 0; i < d.length; i++) {
if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; }
if (! text) { if (! text) {
title = titleFormat ? titleFormat(d[i].x) : d[i].x; title = titleFormat ? titleFormat(d[i].x) : d[i].x;
text = "<table class='" + CLASS.tooltip + "'>" + (title || title === 0 ? "<tr><th colspan='2'>" + title + "</th></tr>" : ""); text = "<table class='" + CLASS.tooltip + "'>" + (title || title === 0 ? "<tr><th colspan='2'>" + title + "</th></tr>" : "");
} }
value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index);
if (value !== undefined) { if (value !== undefined) {
name = nameFormat(d[i].name, d[i].ratio, d[i].id, d[i].index); name = nameFormat(d[i].name, d[i].ratio, d[i].id, d[i].index);
bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id);
text += "<tr class='" + CLASS.tooltipName + "-" + d[i].id + "'>"; text += "<tr class='" + CLASS.tooltipName + "-" + d[i].id + "'>";
text += "<td class='name'><span style='background-color:" + bgcolor + "'></span>" + name + "</td>"; text += "<td class='name'><span style='background-color:" + bgcolor + "'></span>" + name + "</td>";
text += "<td class='value'>" + value + "</td>"; text += "<td class='value'>" + value + "</td>";
...@@ -3802,7 +3804,7 @@ ...@@ -3802,7 +3804,7 @@
chartRight = svgLeft + $$.currentWidth - $$.getCurrentPaddingRight(); chartRight = svgLeft + $$.currentWidth - $$.getCurrentPaddingRight();
tooltipTop = mouse[1] + 15; tooltipTop = mouse[1] + 15;
} }
if (tooltipRight > chartRight) { if (tooltipRight > chartRight) {
// 20 is needed for Firefox to keep tooletip width // 20 is needed for Firefox to keep tooletip width
tooltipLeft -= tooltipRight - chartRight + 20; tooltipLeft -= tooltipRight - chartRight + 20;
...@@ -3826,11 +3828,11 @@ ...@@ -3826,11 +3828,11 @@
return; return;
} }
$$.tooltip.html(config.tooltip_contents.call($$, selectedData, $$.axis.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); $$.tooltip.html(config.tooltip_contents.call($$, selectedData, $$.axis.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block");
// Get tooltip dimensions // Get tooltip dimensions
tWidth = $$.tooltip.property('offsetWidth'); tWidth = $$.tooltip.property('offsetWidth');
tHeight = $$.tooltip.property('offsetHeight'); tHeight = $$.tooltip.property('offsetHeight');
position = positionFunction.call(this, dataToShow, tWidth, tHeight, element); position = positionFunction.call(this, dataToShow, tWidth, tHeight, element);
// Set tooltip // Set tooltip
$$.tooltip $$.tooltip
...@@ -3864,7 +3866,7 @@ ...@@ -3864,7 +3866,7 @@
top: $$.isLegendTop ? $$.getCurrentPaddingTop() + config.legend_inset_y + 5.5 : $$.currentHeight - legendHeight - $$.getCurrentPaddingBottom() - config.legend_inset_y, top: $$.isLegendTop ? $$.getCurrentPaddingTop() + config.legend_inset_y + 5.5 : $$.currentHeight - legendHeight - $$.getCurrentPaddingBottom() - config.legend_inset_y,
left: $$.isLegendLeft ? $$.getCurrentPaddingLeft() + config.legend_inset_x + 0.5 : $$.currentWidth - legendWidth - $$.getCurrentPaddingRight() - config.legend_inset_x + 0.5 left: $$.isLegendLeft ? $$.getCurrentPaddingLeft() + config.legend_inset_x + 0.5 : $$.currentWidth - legendWidth - $$.getCurrentPaddingRight() - config.legend_inset_x + 0.5
}; };
$$.margin3 = { $$.margin3 = {
top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight,
right: NaN, right: NaN,
...@@ -3961,18 +3963,18 @@ ...@@ -3961,18 +3963,18 @@
var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0;
var withTransition, withTransitionForTransform; var withTransition, withTransitionForTransform;
var texts, rects, tiles, background; var texts, rects, tiles, background;
options = options || {}; options = options || {};
withTransition = getOption(options, "withTransition", true); withTransition = getOption(options, "withTransition", true);
withTransitionForTransform = getOption(options, "withTransitionForTransform", true); withTransitionForTransform = getOption(options, "withTransitionForTransform", true);
function getTextBox(textElement, id) { function getTextBox(textElement, id) {
if (!$$.legendItemTextBox[id]) { if (!$$.legendItemTextBox[id]) {
$$.legendItemTextBox[id] = $$.getTextRect(textElement.textContent, CLASS.legendItem); $$.legendItemTextBox[id] = $$.getTextRect(textElement.textContent, CLASS.legendItem);
} }
return $$.legendItemTextBox[id]; return $$.legendItemTextBox[id];
} }
function updatePositions(textElement, id, index) { function updatePositions(textElement, id, index) {
var reset = index === 0, isLast = index === targetIds.length - 1, var reset = index === 0, isLast = index === targetIds.length - 1,
box = getTextBox(textElement, id), box = getTextBox(textElement, id),
...@@ -3981,7 +3983,7 @@ ...@@ -3981,7 +3983,7 @@
itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth,
areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(),
margin, maxLength; margin, maxLength;
// MEMO: care about condifion of step, totalLength // MEMO: care about condifion of step, totalLength
function updateValues(id, withoutStep) { function updateValues(id, withoutStep) {
if (!withoutStep) { if (!withoutStep) {
...@@ -3997,26 +3999,26 @@ ...@@ -3997,26 +3999,26 @@
offsets[id] = totalLength; offsets[id] = totalLength;
totalLength += itemLength; totalLength += itemLength;
} }
if (reset) { if (reset) {
totalLength = 0; totalLength = 0;
step = 0; step = 0;
maxWidth = 0; maxWidth = 0;
maxHeight = 0; maxHeight = 0;
} }
if (config.legend_show && !$$.isLegendToShow(id)) { if (config.legend_show && !$$.isLegendToShow(id)) {
widths[id] = heights[id] = steps[id] = offsets[id] = 0; widths[id] = heights[id] = steps[id] = offsets[id] = 0;
return; return;
} }
widths[id] = itemWidth; widths[id] = itemWidth;
heights[id] = itemHeight; heights[id] = itemHeight;
if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; }
if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; }
maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth;
if (config.legend_equally) { if (config.legend_equally) {
Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; });
Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; });
...@@ -4033,12 +4035,12 @@ ...@@ -4033,12 +4035,12 @@
updateValues(id); updateValues(id);
} }
} }
if ($$.isLegendInset) { if ($$.isLegendInset) {
step = config.legend_inset_step ? config.legend_inset_step : targetIds.length; step = config.legend_inset_step ? config.legend_inset_step : targetIds.length;
$$.updateLegendStep(step); $$.updateLegendStep(step);
} }
if ($$.isLegendRight) { if ($$.isLegendRight) {
xForLegend = function (id) { return maxWidth * steps[id]; }; xForLegend = function (id) { return maxWidth * steps[id]; };
yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; yForLegend = function (id) { return margins[steps[id]] + offsets[id]; };
...@@ -4053,7 +4055,7 @@ ...@@ -4053,7 +4055,7 @@
yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; yForLegendText = function (id, i) { return yForLegend(id, i) + 9; };
xForLegendRect = function (id, i) { return xForLegend(id, i); }; xForLegendRect = function (id, i) { return xForLegend(id, i); };
yForLegendRect = function (id, i) { return yForLegend(id, i) - 5; }; yForLegendRect = function (id, i) { return yForLegend(id, i) - 5; };
// Define g for legend area // Define g for legend area
l = $$.legend.selectAll('.' + CLASS.legendItem) l = $$.legend.selectAll('.' + CLASS.legendItem)
.data(targetIds) .data(targetIds)
...@@ -4109,7 +4111,7 @@ ...@@ -4109,7 +4111,7 @@
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend)
.attr('width', 10) .attr('width', 10)
.attr('height', 10); .attr('height', 10);
// Set background for inset legend // Set background for inset legend
background = $$.legend.select('.' + CLASS.legendBackground + ' rect'); background = $$.legend.select('.' + CLASS.legendBackground + ' rect');
if ($$.isLegendInset && maxWidth > 0 && background.size() === 0) { if ($$.isLegendInset && maxWidth > 0 && background.size() === 0) {
...@@ -4117,7 +4119,7 @@ ...@@ -4117,7 +4119,7 @@
.attr("class", CLASS.legendBackground) .attr("class", CLASS.legendBackground)
.append('rect'); .append('rect');
} }
texts = $$.legend.selectAll('text') texts = $$.legend.selectAll('text')
.data(targetIds) .data(targetIds)
.text(function (id) { return isDefined(config.data_names[id]) ? config.data_names[id] : id; }) // MEMO: needed for update .text(function (id) { return isDefined(config.data_names[id]) ? config.data_names[id] : id; }) // MEMO: needed for update
...@@ -4125,7 +4127,7 @@ ...@@ -4125,7 +4127,7 @@
(withTransition ? texts.transition() : texts) (withTransition ? texts.transition() : texts)
.attr('x', xForLegendText) .attr('x', xForLegendText)
.attr('y', yForLegendText); .attr('y', yForLegendText);
rects = $$.legend.selectAll('rect.' + CLASS.legendItemEvent) rects = $$.legend.selectAll('rect.' + CLASS.legendItemEvent)
.data(targetIds); .data(targetIds);
(withTransition ? rects.transition() : rects) (withTransition ? rects.transition() : rects)
...@@ -4133,24 +4135,24 @@ ...@@ -4133,24 +4135,24 @@
.attr('height', function (id) { return heights[id]; }) .attr('height', function (id) { return heights[id]; })
.attr('x', xForLegendRect) .attr('x', xForLegendRect)
.attr('y', yForLegendRect); .attr('y', yForLegendRect);
tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile) tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile)
.data(targetIds); .data(targetIds);
(withTransition ? tiles.transition() : tiles) (withTransition ? tiles.transition() : tiles)
.style('fill', $$.color) .style('fill', $$.color)
.attr('x', xForLegend) .attr('x', xForLegend)
.attr('y', yForLegend); .attr('y', yForLegend);
if (background) { if (background) {
(withTransition ? background.transition() : background) (withTransition ? background.transition() : background)
.attr('height', $$.getLegendHeight() - 12) .attr('height', $$.getLegendHeight() - 12)
.attr('width', maxWidth * (step + 1) + 10); .attr('width', maxWidth * (step + 1) + 10);
} }
// toggle legend state // toggle legend state
$$.legend.selectAll('.' + CLASS.legendItem) $$.legend.selectAll('.' + CLASS.legendItem)
.classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }); .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); });
// Update all to reflect change of legend // Update all to reflect change of legend
$$.updateLegendItemWidth(maxWidth); $$.updateLegendItemWidth(maxWidth);
$$.updateLegendItemHeight(maxHeight); $$.updateLegendItemHeight(maxHeight);
...@@ -4199,11 +4201,11 @@ ...@@ -4199,11 +4201,11 @@
function Axis(owner) { function Axis(owner) {
API.call(this, owner); API.call(this, owner);
} }
inherit(API, Axis); inherit(API, Axis);
Axis.prototype.init = function init() { Axis.prototype.init = function init() {
var $$ = this.owner, config = $$.config, main = $$.main; var $$ = this.owner, config = $$.config, main = $$.main;
$$.axes.x = main.append("g") $$.axes.x = main.append("g")
.attr("class", CLASS.axis + ' ' + CLASS.axisX) .attr("class", CLASS.axis + ' ' + CLASS.axisX)
...@@ -4223,7 +4225,7 @@ ...@@ -4223,7 +4225,7 @@
.attr("class", CLASS.axisYLabel) .attr("class", CLASS.axisYLabel)
.attr("transform", config.axis_rotated ? "" : "rotate(-90)") .attr("transform", config.axis_rotated ? "" : "rotate(-90)")
.style("text-anchor", this.textAnchorForYAxisLabel.bind(this)); .style("text-anchor", this.textAnchorForYAxisLabel.bind(this));
$$.axes.y2 = main.append("g") $$.axes.y2 = main.append("g")
.attr("class", CLASS.axis + ' ' + CLASS.axisY2) .attr("class", CLASS.axis + ' ' + CLASS.axisY2)
// clip-path? // clip-path?
...@@ -4245,11 +4247,11 @@ ...@@ -4245,11 +4247,11 @@
withoutTransition: withoutTransition, withoutTransition: withoutTransition,
}, },
axis = c3_axis($$.d3, axisParams).scale(scale).orient(orient); axis = c3_axis($$.d3, axisParams).scale(scale).orient(orient);
if ($$.isTimeSeries() && tickValues) { if ($$.isTimeSeries() && tickValues) {
tickValues = tickValues.map(function (v) { return $$.parseDate(v); }); tickValues = tickValues.map(function (v) { return $$.parseDate(v); });
} }
// Set tick // Set tick
axis.tickFormat(tickFormat).tickValues(tickValues); axis.tickFormat(tickFormat).tickValues(tickValues);
if ($$.isCategorized()) { if ($$.isCategorized()) {
...@@ -4258,7 +4260,7 @@ ...@@ -4258,7 +4260,7 @@
config.axis_x_tick_culling = false; config.axis_x_tick_culling = false;
} }
} }
return axis; return axis;
}; };
Axis.prototype.updateXAxisTickValues = function updateXAxisTickValues(targets, axis) { Axis.prototype.updateXAxisTickValues = function updateXAxisTickValues(targets, axis) {
...@@ -4496,7 +4498,7 @@ ...@@ -4496,7 +4498,7 @@
$$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth; $$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth;
return $$.currentMaxTickWidths[id]; return $$.currentMaxTickWidths[id];
}; };
Axis.prototype.updateLabels = function updateLabels(withTransition) { Axis.prototype.updateLabels = function updateLabels(withTransition) {
var $$ = this.owner; var $$ = this.owner;
var axisXLabel = $$.main.select('.' + CLASS.axisX + ' .' + CLASS.axisXLabel), var axisXLabel = $$.main.select('.' + CLASS.axisX + ' .' + CLASS.axisXLabel),
...@@ -4648,7 +4650,7 @@ ...@@ -4648,7 +4650,7 @@
$$.pie.sort(null); $$.pie.sort(null);
} }
}; };
c3_chart_internal_fn.updateRadius = function () { c3_chart_internal_fn.updateRadius = function () {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
w = config.gauge_width || config.donut_width; w = config.gauge_width || config.donut_width;
...@@ -4657,14 +4659,14 @@ ...@@ -4657,14 +4659,14 @@
$$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6;
$$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0; $$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0;
}; };
c3_chart_internal_fn.updateArc = function () { c3_chart_internal_fn.updateArc = function () {
var $$ = this; var $$ = this;
$$.svgArc = $$.getSvgArc(); $$.svgArc = $$.getSvgArc();
$$.svgArcExpanded = $$.getSvgArcExpanded(); $$.svgArcExpanded = $$.getSvgArcExpanded();
$$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98);
}; };
c3_chart_internal_fn.updateAngle = function (d) { c3_chart_internal_fn.updateAngle = function (d) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
found = false, index = 0, found = false, index = 0,
...@@ -4691,7 +4693,7 @@ ...@@ -4691,7 +4693,7 @@
} }
return found ? d : null; return found ? d : null;
}; };
c3_chart_internal_fn.getSvgArc = function () { c3_chart_internal_fn.getSvgArc = function () {
var $$ = this, var $$ = this,
arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius),
...@@ -4705,7 +4707,7 @@ ...@@ -4705,7 +4707,7 @@
newArc.centroid = arc.centroid; newArc.centroid = arc.centroid;
return newArc; return newArc;
}; };
c3_chart_internal_fn.getSvgArcExpanded = function (rate) { c3_chart_internal_fn.getSvgArcExpanded = function (rate) {
var $$ = this, var $$ = this,
arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius);
...@@ -4714,12 +4716,12 @@ ...@@ -4714,12 +4716,12 @@
return updated ? arc(updated) : "M 0 0"; return updated ? arc(updated) : "M 0 0";
}; };
}; };
c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) {
return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
}; };
c3_chart_internal_fn.transformForArcLabel = function (d) { c3_chart_internal_fn.transformForArcLabel = function (d) {
var $$ = this, var $$ = this,
updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; updated = $$.updateAngle(d), c, x, y, h, ratio, translate = "";
...@@ -4734,13 +4736,13 @@ ...@@ -4734,13 +4736,13 @@
} }
return translate; return translate;
}; };
c3_chart_internal_fn.getArcRatio = function (d) { c3_chart_internal_fn.getArcRatio = function (d) {
var $$ = this, var $$ = this,
whole = $$.hasType('gauge') ? Math.PI : (Math.PI * 2); whole = $$.hasType('gauge') ? Math.PI : (Math.PI * 2);
return d ? (d.endAngle - d.startAngle) / whole : null; return d ? (d.endAngle - d.startAngle) / whole : null;
}; };
c3_chart_internal_fn.convertToArcData = function (d) { c3_chart_internal_fn.convertToArcData = function (d) {
return this.addName({ return this.addName({
id: d.data.id, id: d.data.id,
...@@ -4749,7 +4751,7 @@ ...@@ -4749,7 +4751,7 @@
index: d.index index: d.index
}); });
}; };
c3_chart_internal_fn.textForArcLabel = function (d) { c3_chart_internal_fn.textForArcLabel = function (d) {
var $$ = this, var $$ = this,
updated, value, ratio, id, format; updated, value, ratio, id, format;
...@@ -4762,10 +4764,10 @@ ...@@ -4762,10 +4764,10 @@
format = $$.getArcLabelFormat(); format = $$.getArcLabelFormat();
return format ? format(value, ratio, id) : $$.defaultArcValueFormat(value, ratio); return format ? format(value, ratio, id) : $$.defaultArcValueFormat(value, ratio);
}; };
c3_chart_internal_fn.expandArc = function (targetIds) { c3_chart_internal_fn.expandArc = function (targetIds) {
var $$ = this, interval; var $$ = this, interval;
// MEMO: avoid to cancel transition // MEMO: avoid to cancel transition
if ($$.transiting) { if ($$.transiting) {
interval = window.setInterval(function () { interval = window.setInterval(function () {
...@@ -4778,9 +4780,9 @@ ...@@ -4778,9 +4780,9 @@
}, 10); }, 10);
return; return;
} }
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
$$.svg.selectAll($$.selectorTargets(targetIds, '.' + CLASS.chartArc)).each(function (d) { $$.svg.selectAll($$.selectorTargets(targetIds, '.' + CLASS.chartArc)).each(function (d) {
if (! $$.shouldExpand(d.data.id)) { return; } if (! $$.shouldExpand(d.data.id)) { return; }
$$.d3.select(this).selectAll('path') $$.d3.select(this).selectAll('path')
...@@ -4795,26 +4797,26 @@ ...@@ -4795,26 +4797,26 @@
}); });
}); });
}; };
c3_chart_internal_fn.unexpandArc = function (targetIds) { c3_chart_internal_fn.unexpandArc = function (targetIds) {
var $$ = this; var $$ = this;
if ($$.transiting) { return; } if ($$.transiting) { return; }
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
$$.svg.selectAll($$.selectorTargets(targetIds, '.' + CLASS.chartArc)).selectAll('path') $$.svg.selectAll($$.selectorTargets(targetIds, '.' + CLASS.chartArc)).selectAll('path')
.transition().duration(50) .transition().duration(50)
.attr("d", $$.svgArc); .attr("d", $$.svgArc);
$$.svg.selectAll('.' + CLASS.arc) $$.svg.selectAll('.' + CLASS.arc)
.style("opacity", 1); .style("opacity", 1);
}; };
c3_chart_internal_fn.shouldExpand = function (id) { c3_chart_internal_fn.shouldExpand = function (id) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
return ($$.isDonutType(id) && config.donut_expand) || ($$.isGaugeType(id) && config.gauge_expand) || ($$.isPieType(id) && config.pie_expand); return ($$.isDonutType(id) && config.donut_expand) || ($$.isGaugeType(id) && config.gauge_expand) || ($$.isPieType(id) && config.pie_expand);
}; };
c3_chart_internal_fn.shouldShowArcLabel = function () { c3_chart_internal_fn.shouldShowArcLabel = function () {
var $$ = this, config = $$.config, shouldShow = true; var $$ = this, config = $$.config, shouldShow = true;
if ($$.hasType('donut')) { if ($$.hasType('donut')) {
...@@ -4825,13 +4827,13 @@ ...@@ -4825,13 +4827,13 @@
// when gauge, always true // when gauge, always true
return shouldShow; return shouldShow;
}; };
c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
threshold = $$.hasType('donut') ? config.donut_label_threshold : config.pie_label_threshold; threshold = $$.hasType('donut') ? config.donut_label_threshold : config.pie_label_threshold;
return ratio >= threshold; return ratio >= threshold;
}; };
c3_chart_internal_fn.getArcLabelFormat = function () { c3_chart_internal_fn.getArcLabelFormat = function () {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
format = config.pie_label_format; format = config.pie_label_format;
...@@ -4842,12 +4844,12 @@ ...@@ -4842,12 +4844,12 @@
} }
return format; return format;
}; };
c3_chart_internal_fn.getArcTitle = function () { c3_chart_internal_fn.getArcTitle = function () {
var $$ = this; var $$ = this;
return $$.hasType('donut') ? $$.config.donut_title : ""; return $$.hasType('donut') ? $$.config.donut_title : "";
}; };
c3_chart_internal_fn.updateTargetsForArc = function (targets) { c3_chart_internal_fn.updateTargetsForArc = function (targets) {
var $$ = this, main = $$.main, var $$ = this, main = $$.main,
mainPieUpdate, mainPieEnter, mainPieUpdate, mainPieEnter,
...@@ -4869,7 +4871,7 @@ ...@@ -4869,7 +4871,7 @@
// MEMO: can not keep same color..., but not bad to update color in redraw // MEMO: can not keep same color..., but not bad to update color in redraw
//mainPieUpdate.exit().remove(); //mainPieUpdate.exit().remove();
}; };
c3_chart_internal_fn.initArc = function () { c3_chart_internal_fn.initArc = function () {
var $$ = this; var $$ = this;
$$.arcs = $$.main.select('.' + CLASS.chart).append("g") $$.arcs = $$.main.select('.' + CLASS.chart).append("g")
...@@ -4880,7 +4882,7 @@ ...@@ -4880,7 +4882,7 @@
.style("text-anchor", "middle") .style("text-anchor", "middle")
.text($$.getArcTitle()); .text($$.getArcTitle());
}; };
c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) {
var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main,
mainArc; mainArc;
...@@ -4987,7 +4989,7 @@ ...@@ -4987,7 +4989,7 @@
.style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; });
main.select('.' + CLASS.chartArcsTitle) main.select('.' + CLASS.chartArcsTitle)
.style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0); .style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0);
if ($$.hasType('gauge')) { if ($$.hasType('gauge')) {
$$.arcs.select('.' + CLASS.chartArcsBackground) $$.arcs.select('.' + CLASS.chartArcsBackground)
.attr("d", function () { .attr("d", function () {
...@@ -5042,10 +5044,10 @@ ...@@ -5042,10 +5044,10 @@
}; };
c3_chart_internal_fn.updateRegion = function (duration) { c3_chart_internal_fn.updateRegion = function (duration) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
// hide if arc type // hide if arc type
$$.region.style('visibility', $$.hasArcType() ? 'hidden' : 'visible'); $$.region.style('visibility', $$.hasArcType() ? 'hidden' : 'visible');
$$.mainRegion = $$.main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) $$.mainRegion = $$.main.select('.' + CLASS.regions).selectAll('.' + CLASS.region)
.data(config.regions); .data(config.regions);
$$.mainRegion.enter().append('g') $$.mainRegion.enter().append('g')
...@@ -5119,12 +5121,12 @@ ...@@ -5119,12 +5121,12 @@
c3_chart_internal_fn.drag = function (mouse) { c3_chart_internal_fn.drag = function (mouse) {
var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3;
var sx, sy, mx, my, minX, maxX, minY, maxY; var sx, sy, mx, my, minX, maxX, minY, maxY;
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
if (! config.data_selection_enabled) { return; } // do nothing if not selectable if (! config.data_selection_enabled) { return; } // do nothing if not selectable
if (config.zoom_enabled && ! $$.zoom.altDomain) { return; } // skip if zoomable because of conflict drag dehavior if (config.zoom_enabled && ! $$.zoom.altDomain) { return; } // skip if zoomable because of conflict drag dehavior
if (!config.data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection if (!config.data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection
sx = $$.dragStart[0]; sx = $$.dragStart[0];
sy = $$.dragStart[1]; sy = $$.dragStart[1];
mx = mouse[0]; mx = mouse[0];
...@@ -5133,7 +5135,7 @@ ...@@ -5133,7 +5135,7 @@
maxX = Math.max(sx, mx); maxX = Math.max(sx, mx);
minY = (config.data_selection_grouped) ? $$.margin.top : Math.min(sy, my); minY = (config.data_selection_grouped) ? $$.margin.top : Math.min(sy, my);
maxY = (config.data_selection_grouped) ? $$.height : Math.max(sy, my); maxY = (config.data_selection_grouped) ? $$.height : Math.max(sy, my);
main.select('.' + CLASS.dragarea) main.select('.' + CLASS.dragarea)
.attr('x', minX) .attr('x', minX)
.attr('y', minY) .attr('y', minY)
...@@ -5173,7 +5175,7 @@ ...@@ -5173,7 +5175,7 @@
} }
}); });
}; };
c3_chart_internal_fn.dragstart = function (mouse) { c3_chart_internal_fn.dragstart = function (mouse) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
...@@ -5184,7 +5186,7 @@ ...@@ -5184,7 +5186,7 @@
.style('opacity', 0.1); .style('opacity', 0.1);
$$.dragging = true; $$.dragging = true;
}; };
c3_chart_internal_fn.dragend = function () { c3_chart_internal_fn.dragend = function () {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
...@@ -5261,7 +5263,7 @@ ...@@ -5261,7 +5263,7 @@
var $$ = this, d3 = $$.d3, config = $$.config, var $$ = this, d3 = $$.d3, config = $$.config,
shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED),
toggle = $$.getToggle(that, d).bind($$); toggle = $$.getToggle(that, d).bind($$);
if (config.data_selection_enabled && config.data_selection_isselectable(d)) { if (config.data_selection_enabled && config.data_selection_isselectable(d)) {
if (!config.data_selection_multiple) { if (!config.data_selection_multiple) {
$$.main.selectAll('.' + CLASS.shapes + (config.data_selection_grouped ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { $$.main.selectAll('.' + CLASS.shapes + (config.data_selection_grouped ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) {
...@@ -5288,28 +5290,28 @@ ...@@ -5288,28 +5290,28 @@
c3_chart_internal_fn.initSubchart = function () { c3_chart_internal_fn.initSubchart = function () {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
context = $$.context = $$.svg.append("g").attr("transform", $$.getTranslate('context')); context = $$.context = $$.svg.append("g").attr("transform", $$.getTranslate('context'));
context.style('visibility', config.subchart_show ? 'visible' : 'hidden'); context.style('visibility', config.subchart_show ? 'visible' : 'hidden');
// Define g for chart area // Define g for chart area
context.append('g') context.append('g')
.attr("clip-path", $$.clipPathForSubchart) .attr("clip-path", $$.clipPathForSubchart)
.attr('class', CLASS.chart); .attr('class', CLASS.chart);
// Define g for bar chart area // Define g for bar chart area
context.select('.' + CLASS.chart).append("g") context.select('.' + CLASS.chart).append("g")
.attr("class", CLASS.chartBars); .attr("class", CLASS.chartBars);
// Define g for line chart area // Define g for line chart area
context.select('.' + CLASS.chart).append("g") context.select('.' + CLASS.chart).append("g")
.attr("class", CLASS.chartLines); .attr("class", CLASS.chartLines);
// Add extent rect for Brush // Add extent rect for Brush
context.append("g") context.append("g")
.attr("clip-path", $$.clipPath) .attr("clip-path", $$.clipPath)
.attr("class", CLASS.brush) .attr("class", CLASS.brush)
.call($$.brush); .call($$.brush);
// ATTENTION: This must be called AFTER chart added // ATTENTION: This must be called AFTER chart added
// Add Axis // Add Axis
$$.axes.subx = context.append("g") $$.axes.subx = context.append("g")
...@@ -5325,7 +5327,7 @@ ...@@ -5325,7 +5327,7 @@
classChartLine = $$.classChartLine.bind($$), classChartLine = $$.classChartLine.bind($$),
classLines = $$.classLines.bind($$), classLines = $$.classLines.bind($$),
classAreas = $$.classAreas.bind($$); classAreas = $$.classAreas.bind($$);
if (config.subchart_show) { if (config.subchart_show) {
//-- Bar --// //-- Bar --//
contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar)
...@@ -5337,7 +5339,7 @@ ...@@ -5337,7 +5339,7 @@
// 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) contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine)
.data(targets) .data(targets)
...@@ -5351,7 +5353,7 @@ ...@@ -5351,7 +5353,7 @@
// Area // Area
contextLineEnter.append("g") contextLineEnter.append("g")
.attr("class", classAreas); .attr("class", classAreas);
//-- Brush --// //-- Brush --//
context.selectAll('.' + CLASS.brush + ' rect') context.selectAll('.' + CLASS.brush + ' rect')
.attr(config.axis_rotated ? "width" : "height", config.axis_rotated ? $$.width2 : $$.height2); .attr(config.axis_rotated ? "width" : "height", config.axis_rotated ? $$.width2 : $$.height2);
...@@ -5417,9 +5419,9 @@ ...@@ -5417,9 +5419,9 @@
c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) {
var $$ = this, d3 = $$.d3, config = $$.config, var $$ = this, d3 = $$.d3, config = $$.config,
drawAreaOnSub, drawBarOnSub, drawLineOnSub; drawAreaOnSub, drawBarOnSub, drawLineOnSub;
$$.context.style('visibility', config.subchart_show ? 'visible' : 'hidden'); $$.context.style('visibility', config.subchart_show ? 'visible' : 'hidden');
// subchart // subchart
if (config.subchart_show) { if (config.subchart_show) {
// reflect main chart to extent on subchart if zoomed // reflect main chart to extent on subchart if zoomed
...@@ -5428,7 +5430,7 @@ ...@@ -5428,7 +5430,7 @@
} }
// update subchart elements if needed // update subchart elements if needed
if (withSubchart) { if (withSubchart) {
// extent rect // extent rect
if (!$$.brush.empty()) { if (!$$.brush.empty()) {
$$.brush.extent($$.x.orgDomain()).update(); $$.brush.extent($$.x.orgDomain()).update();
...@@ -5437,11 +5439,11 @@ ...@@ -5437,11 +5439,11 @@
drawAreaOnSub = $$.generateDrawArea(areaIndices, true); drawAreaOnSub = $$.generateDrawArea(areaIndices, true);
drawBarOnSub = $$.generateDrawBar(barIndices, true); drawBarOnSub = $$.generateDrawBar(barIndices, true);
drawLineOnSub = $$.generateDrawLine(lineIndices, true); drawLineOnSub = $$.generateDrawLine(lineIndices, true);
$$.updateBarForSubchart(duration); $$.updateBarForSubchart(duration);
$$.updateLineForSubchart(duration); $$.updateLineForSubchart(duration);
$$.updateAreaForSubchart(duration); $$.updateAreaForSubchart(duration);
$$.redrawBarForSubchart(drawBarOnSub, duration, duration); $$.redrawBarForSubchart(drawBarOnSub, duration, duration);
$$.redrawLineForSubchart(drawLineOnSub, duration, duration); $$.redrawLineForSubchart(drawLineOnSub, duration, duration);
$$.redrawAreaForSubchart(drawAreaOnSub, duration, duration); $$.redrawAreaForSubchart(drawAreaOnSub, duration, duration);
...@@ -5481,7 +5483,7 @@ ...@@ -5481,7 +5483,7 @@
c3_chart_internal_fn.initZoom = function () { c3_chart_internal_fn.initZoom = function () {
var $$ = this, d3 = $$.d3, config = $$.config, startEvent; var $$ = this, d3 = $$.d3, config = $$.config, startEvent;
$$.zoom = d3.behavior.zoom() $$.zoom = d3.behavior.zoom()
.on("zoomstart", function () { .on("zoomstart", function () {
startEvent = d3.event.sourceEvent; startEvent = d3.event.sourceEvent;
...@@ -5555,10 +5557,10 @@ ...@@ -5555,10 +5557,10 @@
pattern = notEmpty(config.color_pattern) ? config.color_pattern : d3.scale.category10().range(), pattern = notEmpty(config.color_pattern) ? config.color_pattern : d3.scale.category10().range(),
callback = config.data_color, callback = config.data_color,
ids = []; ids = [];
return function (d) { return function (d) {
var id = d.id || (d.data && d.data.id) || d, color; var id = d.id || (d.data && d.data.id) || d, color;
// if callback function is provided // if callback function is provided
if (colors[id] instanceof Function) { if (colors[id] instanceof Function) {
color = colors[id](d); color = colors[id](d);
...@@ -5881,10 +5883,10 @@ ...@@ -5881,10 +5883,10 @@
c3_chart_fn.focus = function (targetIds) { c3_chart_fn.focus = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$))), candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$))),
this.revert(); this.revert();
this.defocus(); this.defocus();
candidates.classed(CLASS.focused, true).classed(CLASS.defocused, false); candidates.classed(CLASS.focused, true).classed(CLASS.defocused, false);
...@@ -5892,37 +5894,37 @@ ...@@ -5892,37 +5894,37 @@
$$.expandArc(targetIds); $$.expandArc(targetIds);
} }
$$.toggleFocusLegend(targetIds, true); $$.toggleFocusLegend(targetIds, true);
$$.focusedTargetIds = targetIds; $$.focusedTargetIds = targetIds;
$$.defocusedTargetIds = $$.defocusedTargetIds.filter(function (id) { $$.defocusedTargetIds = $$.defocusedTargetIds.filter(function (id) {
return targetIds.indexOf(id) < 0; return targetIds.indexOf(id) < 0;
}); });
}; };
c3_chart_fn.defocus = function (targetIds) { c3_chart_fn.defocus = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$))), candidates = $$.svg.selectAll($$.selectorTargets(targetIds.filter($$.isTargetToShow, $$))),
candidates.classed(CLASS.focused, false).classed(CLASS.defocused, true); candidates.classed(CLASS.focused, false).classed(CLASS.defocused, true);
if ($$.hasArcType()) { if ($$.hasArcType()) {
$$.unexpandArc(targetIds); $$.unexpandArc(targetIds);
} }
$$.toggleFocusLegend(targetIds, false); $$.toggleFocusLegend(targetIds, false);
$$.focusedTargetIds = $$.focusedTargetIds.filter(function (id) { $$.focusedTargetIds = $$.focusedTargetIds.filter(function (id) {
return targetIds.indexOf(id) < 0; return targetIds.indexOf(id) < 0;
}); });
$$.defocusedTargetIds = targetIds; $$.defocusedTargetIds = targetIds;
}; };
c3_chart_fn.revert = function (targetIds) { c3_chart_fn.revert = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
candidates = $$.svg.selectAll($$.selectorTargets(targetIds)); // should be for all targets candidates = $$.svg.selectAll($$.selectorTargets(targetIds)); // should be for all targets
candidates.classed(CLASS.focused, false).classed(CLASS.defocused, false); candidates.classed(CLASS.focused, false).classed(CLASS.defocused, false);
if ($$.hasArcType()) { if ($$.hasArcType()) {
$$.unexpandArc(targetIds); $$.unexpandArc(targetIds);
...@@ -5935,55 +5937,55 @@ ...@@ -5935,55 +5937,55 @@
}) })
.classed(CLASS.legendItemFocused, false); .classed(CLASS.legendItemFocused, false);
} }
$$.focusedTargetIds = []; $$.focusedTargetIds = [];
$$.defocusedTargetIds = []; $$.defocusedTargetIds = [];
}; };
c3_chart_fn.show = function (targetIds, options) { c3_chart_fn.show = function (targetIds, options) {
var $$ = this.internal, targets; var $$ = this.internal, targets;
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
options = options || {}; options = options || {};
$$.removeHiddenTargetIds(targetIds); $$.removeHiddenTargetIds(targetIds);
targets = $$.svg.selectAll($$.selectorTargets(targetIds)); targets = $$.svg.selectAll($$.selectorTargets(targetIds));
targets.transition() targets.transition()
.style('opacity', 1, 'important') .style('opacity', 1, 'important')
.call($$.endall, function () { .call($$.endall, function () {
targets.style('opacity', null).style('opacity', 1); targets.style('opacity', null).style('opacity', 1);
}); });
if (options.withLegend) { if (options.withLegend) {
$$.showLegend(targetIds); $$.showLegend(targetIds);
} }
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
}; };
c3_chart_fn.hide = function (targetIds, options) { c3_chart_fn.hide = function (targetIds, options) {
var $$ = this.internal, targets; var $$ = this.internal, targets;
targetIds = $$.mapToTargetIds(targetIds); targetIds = $$.mapToTargetIds(targetIds);
options = options || {}; options = options || {};
$$.addHiddenTargetIds(targetIds); $$.addHiddenTargetIds(targetIds);
targets = $$.svg.selectAll($$.selectorTargets(targetIds)); targets = $$.svg.selectAll($$.selectorTargets(targetIds));
targets.transition() targets.transition()
.style('opacity', 0, 'important') .style('opacity', 0, 'important')
.call($$.endall, function () { .call($$.endall, function () {
targets.style('opacity', null).style('opacity', 0); targets.style('opacity', null).style('opacity', 0);
}); });
if (options.withLegend) { if (options.withLegend) {
$$.hideLegend(targetIds); $$.hideLegend(targetIds);
} }
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
}; };
c3_chart_fn.toggle = function (targetIds, options) { c3_chart_fn.toggle = function (targetIds, options) {
var that = this, $$ = this.internal; var that = this, $$ = this.internal;
$$.mapToTargetIds(targetIds).forEach(function (targetId) { $$.mapToTargetIds(targetIds).forEach(function (targetId) {
...@@ -6057,7 +6059,7 @@ ...@@ -6057,7 +6059,7 @@
$$.loadFromArgs(args); $$.loadFromArgs(args);
} }
}; };
c3_chart_fn.unload = function (args) { c3_chart_fn.unload = function (args) {
var $$ = this.internal; var $$ = this.internal;
args = args || {}; args = args || {};
...@@ -6076,7 +6078,7 @@ ...@@ -6076,7 +6078,7 @@
var $$ = this.internal, var $$ = this.internal,
targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(),
dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to;
if (args.json) { if (args.json) {
data = $$.convertJsonToData(args.json, args.keys); data = $$.convertJsonToData(args.json, args.keys);
} }
...@@ -6090,19 +6092,19 @@ ...@@ -6090,19 +6092,19 @@
return; return;
} }
targets = $$.convertDataToTargets(data, true); targets = $$.convertDataToTargets(data, true);
// Update/Add data // Update/Add data
$$.data.targets.forEach(function (t) { $$.data.targets.forEach(function (t) {
var found = false, i, j; var found = false, i, j;
for (i = 0; i < targets.length; i++) { for (i = 0; i < targets.length; i++) {
if (t.id === targets[i].id) { if (t.id === targets[i].id) {
found = true; found = true;
if (t.values[t.values.length - 1]) { if (t.values[t.values.length - 1]) {
tail = t.values[t.values.length - 1].index + 1; tail = t.values[t.values.length - 1].index + 1;
} }
length = targets[i].values.length; length = targets[i].values.length;
for (j = 0; j < length; j++) { for (j = 0; j < length; j++) {
targets[i].values[j].index = tail + j; targets[i].values[j].index = tail + j;
if (!$$.isTimeSeries()) { if (!$$.isTimeSeries()) {
...@@ -6110,14 +6112,14 @@ ...@@ -6110,14 +6112,14 @@
} }
} }
t.values = t.values.concat(targets[i].values); t.values = t.values.concat(targets[i].values);
targets.splice(i, 1); targets.splice(i, 1);
break; break;
} }
} }
if (!found) { notfoundIds.push(t.id); } if (!found) { notfoundIds.push(t.id); }
}); });
// Append null for not found targets // Append null for not found targets
$$.data.targets.forEach(function (t) { $$.data.targets.forEach(function (t) {
var i, j; var i, j;
...@@ -6135,7 +6137,7 @@ ...@@ -6135,7 +6137,7 @@
} }
} }
}); });
// Generate null values for new target // Generate null values for new target
if ($$.data.targets.length) { if ($$.data.targets.length) {
targets.forEach(function (t) { targets.forEach(function (t) {
...@@ -6158,12 +6160,12 @@ ...@@ -6158,12 +6160,12 @@
}); });
} }
$$.data.targets = $$.data.targets.concat(targets); // add remained $$.data.targets = $$.data.targets.concat(targets); // add remained
// check data count because behavior needs to change when it's only one // check data count because behavior needs to change when it's only one
dataCount = $$.getMaxDataCount(); dataCount = $$.getMaxDataCount();
baseTarget = $$.data.targets[0]; baseTarget = $$.data.targets[0];
baseValue = baseTarget.values[0]; baseValue = baseTarget.values[0];
// Update length to flow if needed // Update length to flow if needed
if (isDefined(args.to)) { if (isDefined(args.to)) {
length = 0; length = 0;
...@@ -6174,7 +6176,7 @@ ...@@ -6174,7 +6176,7 @@
} else if (isDefined(args.length)) { } else if (isDefined(args.length)) {
length = args.length; length = args.length;
} }
// If only one data, update the domain to flow from left edge of the chart // If only one data, update the domain to flow from left edge of the chart
if (!orgDataCount) { if (!orgDataCount) {
if ($$.isTimeSeries()) { if ($$.isTimeSeries()) {
...@@ -6195,10 +6197,10 @@ ...@@ -6195,10 +6197,10 @@
$$.updateXDomain(null, true, true, false, domain); $$.updateXDomain(null, true, true, false, domain);
} }
} }
// Set targets // Set targets
$$.updateTargets($$.data.targets); $$.updateTargets($$.data.targets);
// Redraw with new targets // Redraw with new targets
$$.redraw({ $$.redraw({
flow: { flow: {
...@@ -6214,10 +6216,10 @@ ...@@ -6214,10 +6216,10 @@
withUpdateXAxis: true, withUpdateXAxis: true,
}); });
}; };
c3_chart_internal_fn.generateFlow = function (args) { c3_chart_internal_fn.generateFlow = function (args) {
var $$ = this, config = $$.config, d3 = $$.d3; var $$ = this, config = $$.config, d3 = $$.d3;
return function () { return function () {
var targets = args.targets, var targets = args.targets,
flow = args.flow, flow = args.flow,
...@@ -6230,7 +6232,7 @@ ...@@ -6230,7 +6232,7 @@
xForText = args.xForText, xForText = args.xForText,
yForText = args.yForText, yForText = args.yForText,
duration = args.duration; duration = args.duration;
var translateX, scaleX = 1, transform, var translateX, scaleX = 1, transform,
flowIndex = flow.index, flowIndex = flow.index,
flowLength = flow.length, flowLength = flow.length,
...@@ -6240,7 +6242,7 @@ ...@@ -6240,7 +6242,7 @@
durationForFlow = flow.duration || duration, durationForFlow = flow.duration || duration,
done = flow.done || function () {}, done = flow.done || function () {},
wait = $$.generateWait(); wait = $$.generateWait();
var xgrid = $$.xgrid || d3.selectAll([]), var xgrid = $$.xgrid || d3.selectAll([]),
xgridLines = $$.xgridLines || d3.selectAll([]), xgridLines = $$.xgridLines || d3.selectAll([]),
mainRegion = $$.mainRegion || d3.selectAll([]), mainRegion = $$.mainRegion || d3.selectAll([]),
...@@ -6249,20 +6251,20 @@ ...@@ -6249,20 +6251,20 @@
mainLine = $$.mainLine || d3.selectAll([]), mainLine = $$.mainLine || d3.selectAll([]),
mainArea = $$.mainArea || d3.selectAll([]), mainArea = $$.mainArea || d3.selectAll([]),
mainCircle = $$.mainCircle || d3.selectAll([]); mainCircle = $$.mainCircle || d3.selectAll([]);
// set flag // set flag
$$.flowing = true; $$.flowing = true;
// remove head data after rendered // remove head data after rendered
$$.data.targets.forEach(function (d) { $$.data.targets.forEach(function (d) {
d.values.splice(0, flowLength); d.values.splice(0, flowLength);
}); });
// update x domain to generate axis elements for flow // update x domain to generate axis elements for flow
domain = $$.updateXDomain(targets, true, true); domain = $$.updateXDomain(targets, true, true);
// update elements related to x scale // update elements related to x scale
if ($$.updateXGrid) { $$.updateXGrid(true); } if ($$.updateXGrid) { $$.updateXGrid(true); }
// generate transform to flow // generate transform to flow
if (!flow.orgDataCount) { // if empty if (!flow.orgDataCount) { // if empty
if ($$.data.targets[0].values.length !== 1) { if ($$.data.targets[0].values.length !== 1) {
...@@ -6287,11 +6289,11 @@ ...@@ -6287,11 +6289,11 @@
} }
scaleX = (diffDomain(orgDomain) / diffDomain(domain)); scaleX = (diffDomain(orgDomain) / diffDomain(domain));
transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)';
// hide tooltip // hide tooltip
$$.hideXGridFocus(); $$.hideXGridFocus();
$$.hideTooltip(); $$.hideTooltip();
d3.transition().ease('linear').duration(durationForFlow).each(function () { d3.transition().ease('linear').duration(durationForFlow).each(function () {
wait.add($$.axes.x.transition().call($$.xAxis)); wait.add($$.axes.x.transition().call($$.xAxis));
wait.add(mainBar.transition().attr('transform', transform)); wait.add(mainBar.transition().attr('transform', transform));
...@@ -6305,7 +6307,7 @@ ...@@ -6305,7 +6307,7 @@
}) })
.call(wait, function () { .call(wait, function () {
var i, shapes = [], texts = [], eventRects = []; var i, shapes = [], texts = [], eventRects = [];
// remove flowed elements // remove flowed elements
if (flowLength) { if (flowLength) {
for (i = 0; i < flowLength; i++) { for (i = 0; i < flowLength; i++) {
...@@ -6318,7 +6320,7 @@ ...@@ -6318,7 +6320,7 @@
$$.svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); $$.svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove();
$$.svg.select('.' + CLASS.xgrid).remove(); $$.svg.select('.' + CLASS.xgrid).remove();
} }
// draw again for removing flowed elements and reverting attr // draw again for removing flowed elements and reverting attr
xgrid xgrid
.attr('transform', null) .attr('transform', null)
...@@ -6354,14 +6356,14 @@ ...@@ -6354,14 +6356,14 @@
mainRegion.select('rect').filter($$.isRegionOnX) mainRegion.select('rect').filter($$.isRegionOnX)
.attr("x", $$.regionX.bind($$)) .attr("x", $$.regionX.bind($$))
.attr("width", $$.regionWidth.bind($$)); .attr("width", $$.regionWidth.bind($$));
if (config.interaction_enabled) { if (config.interaction_enabled) {
$$.redrawEventRect(); $$.redrawEventRect();
} }
// callback for end of flow // callback for end of flow
done(); done();
$$.flowing = false; $$.flowing = false;
}); });
}; };
...@@ -6427,7 +6429,7 @@ ...@@ -6427,7 +6429,7 @@
options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null;
$$.transformTo(targetIds, type, options); $$.transformTo(targetIds, type, options);
}; };
c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) {
var $$ = this, var $$ = this,
withTransitionForAxis = !$$.hasArcType(), withTransitionForAxis = !$$.hasArcType(),
...@@ -6462,7 +6464,7 @@ ...@@ -6462,7 +6464,7 @@
var $$ = this.internal; var $$ = this.internal;
$$.removeGridLines(params, true); $$.removeGridLines(params, true);
}; };
c3_chart_fn.ygrids = function (grids) { c3_chart_fn.ygrids = function (grids) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
if (! grids) { return config.grid_y_lines; } if (! grids) { return config.grid_y_lines; }
...@@ -6496,16 +6498,16 @@ ...@@ -6496,16 +6498,16 @@
c3_chart_fn.regions.remove = function (options) { c3_chart_fn.regions.remove = function (options) {
var $$ = this.internal, config = $$.config, var $$ = this.internal, config = $$.config,
duration, classes, regions; duration, classes, regions;
options = options || {}; options = options || {};
duration = $$.getOption(options, "duration", config.transition_duration); duration = $$.getOption(options, "duration", config.transition_duration);
classes = $$.getOption(options, "classes", [CLASS.region]); classes = $$.getOption(options, "classes", [CLASS.region]);
regions = $$.main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; })); regions = $$.main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; }));
(duration ? regions.transition().duration(duration) : regions) (duration ? regions.transition().duration(duration) : regions)
.style('opacity', 0) .style('opacity', 0)
.remove(); .remove();
config.regions = config.regions.filter(function (region) { config.regions = config.regions.filter(function (region) {
var found = false; var found = false;
if (!region['class']) { if (!region['class']) {
...@@ -6516,7 +6518,7 @@ ...@@ -6516,7 +6518,7 @@
}); });
return !found; return !found;
}); });
return config.regions; return config.regions;
}; };
...@@ -6666,25 +6668,25 @@ ...@@ -6666,25 +6668,25 @@
config.size_height = size ? size.height : null; config.size_height = size ? size.height : null;
this.flush(); this.flush();
}; };
c3_chart_fn.flush = function () { c3_chart_fn.flush = function () {
var $$ = this.internal; var $$ = this.internal;
$$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false});
}; };
c3_chart_fn.destroy = function () { c3_chart_fn.destroy = function () {
var $$ = this.internal; var $$ = this.internal;
window.clearInterval($$.intervalForObserveInserted); window.clearInterval($$.intervalForObserveInserted);
window.onresize = null; window.onresize = null;
$$.selectChart.classed('c3', false).html(""); $$.selectChart.classed('c3', false).html("");
// MEMO: this is needed because the reference of some elements will not be released, then memory leak will happen. // MEMO: this is needed because the reference of some elements will not be released, then memory leak will happen.
Object.keys($$).forEach(function (key) { Object.keys($$).forEach(function (key) {
$$[key] = null; $$[key] = null;
}); });
return null; return null;
}; };
...@@ -6718,10 +6720,14 @@ ...@@ -6718,10 +6720,14 @@
// emulate mouse events to show // emulate mouse events to show
$$.dispatchEvent('mouseover', index, mouse); $$.dispatchEvent('mouseover', index, mouse);
$$.dispatchEvent('mousemove', index, mouse); $$.dispatchEvent('mousemove', index, mouse);
this.config.tooltip_onshow.call($$, args.data);
}; };
c3_chart_fn.tooltip.hide = function () { c3_chart_fn.tooltip.hide = function () {
// TODO: get target data by checking the state of focus // TODO: get target data by checking the state of focus
this.internal.dispatchEvent('mouseout', 0); this.internal.dispatchEvent('mouseout', 0);
this.config.tooltip_onhide.call(this);
}; };
// Features: // Features:
...@@ -6731,12 +6737,12 @@ ...@@ -6731,12 +6737,12 @@
var tickTextCharSize; var tickTextCharSize;
function c3_axis(d3, params) { function c3_axis(d3, params) {
var scale = d3.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize, tickPadding = 3, tickValues = null, tickFormat, tickArguments; var scale = d3.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize, tickPadding = 3, tickValues = null, tickFormat, tickArguments;
var tickOffset = 0, tickCulling = true, tickCentered; var tickOffset = 0, tickCulling = true, tickCentered;
params = params || {}; params = params || {};
outerTickSize = params.withOuterTick ? 6 : 0; outerTickSize = params.withOuterTick ? 6 : 0;
function axisX(selection, x) { function axisX(selection, x) {
selection.attr("transform", function (d) { selection.attr("transform", function (d) {
return "translate(" + Math.ceil(x(d) + tickOffset) + ", 0)"; return "translate(" + Math.ceil(x(d) + tickOffset) + ", 0)";
...@@ -6804,9 +6810,9 @@ ...@@ -6804,9 +6810,9 @@
function axis(g) { function axis(g) {
g.each(function () { g.each(function () {
var g = axis.g = d3.select(this); var g = axis.g = d3.select(this);
var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = copyScale(); var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = copyScale();
var ticks = tickValues ? tickValues : generateTicks(scale1), var ticks = tickValues ? tickValues : generateTicks(scale1),
tick = g.selectAll(".tick").data(ticks, scale1), tick = g.selectAll(".tick").data(ticks, scale1),
tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", 1e-6), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", 1e-6),
...@@ -6814,18 +6820,18 @@ ...@@ -6814,18 +6820,18 @@
tickExit = tick.exit().remove(), tickExit = tick.exit().remove(),
tickUpdate = transitionise(tick).style("opacity", 1), tickUpdate = transitionise(tick).style("opacity", 1),
tickTransform, tickX, tickY; tickTransform, tickX, tickY;
var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()), var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()),
path = g.selectAll(".domain").data([ 0 ]), path = g.selectAll(".domain").data([ 0 ]),
pathUpdate = (path.enter().append("path").attr("class", "domain"), transitionise(path)); pathUpdate = (path.enter().append("path").attr("class", "domain"), transitionise(path));
tickEnter.append("line"); tickEnter.append("line");
tickEnter.append("text"); tickEnter.append("text");
var lineEnter = tickEnter.select("line"), var lineEnter = tickEnter.select("line"),
lineUpdate = tickUpdate.select("line"), lineUpdate = tickUpdate.select("line"),
textEnter = tickEnter.select("text"), textEnter = tickEnter.select("text"),
textUpdate = tickUpdate.select("text"); textUpdate = tickUpdate.select("text");
if (params.isCategory) { if (params.isCategory) {
tickOffset = Math.ceil((scale1(1) - scale1(0)) / 2); tickOffset = Math.ceil((scale1(1) - scale1(0)) / 2);
tickX = tickCentered ? 0 : tickOffset; tickX = tickCentered ? 0 : tickOffset;
...@@ -6833,24 +6839,24 @@ ...@@ -6833,24 +6839,24 @@
} else { } else {
tickOffset = tickX = 0; tickOffset = tickX = 0;
} }
var text, tspan, sizeFor1Char = getSizeFor1Char(g.select('.tick')), counts = []; var text, tspan, sizeFor1Char = getSizeFor1Char(g.select('.tick')), counts = [];
var tickLength = Math.max(innerTickSize, 0) + tickPadding, var tickLength = Math.max(innerTickSize, 0) + tickPadding,
isVertical = orient === 'left' || orient === 'right'; isVertical = orient === 'left' || orient === 'right';
// this should be called only when category axis // this should be called only when category axis
function splitTickText(d, maxWidth) { function splitTickText(d, maxWidth) {
var tickText = textFormatted(d), var tickText = textFormatted(d),
subtext, spaceIndex, textWidth, splitted = []; subtext, spaceIndex, textWidth, splitted = [];
if (Object.prototype.toString.call(tickText) === "[object Array]") { if (Object.prototype.toString.call(tickText) === "[object Array]") {
return tickText; return tickText;
} }
if (!maxWidth || maxWidth <= 0) { if (!maxWidth || maxWidth <= 0) {
maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 12) : 110; maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 12) : 110;
} }
function split(splitted, text) { function split(splitted, text) {
spaceIndex = undefined; spaceIndex = undefined;
for (var i = 1; i < text.length; i++) { for (var i = 1; i < text.length; i++) {
...@@ -6869,10 +6875,10 @@ ...@@ -6869,10 +6875,10 @@
} }
return splitted.concat(text); return splitted.concat(text);
} }
return split(splitted, tickText + ""); return split(splitted, tickText + "");
} }
function tspanDy(d, i) { function tspanDy(d, i) {
var dy = sizeFor1Char.h; var dy = sizeFor1Char.h;
if (i === 0) { if (i === 0) {
...@@ -6884,12 +6890,12 @@ ...@@ -6884,12 +6890,12 @@
} }
return dy; return dy;
} }
function tickSize(d) { function tickSize(d) {
var tickPosition = scale(d) + (tickCentered ? 0 : tickOffset); var tickPosition = scale(d) + (tickCentered ? 0 : tickOffset);
return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0; return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0;
} }
text = tick.select("text"); text = tick.select("text");
tspan = text.selectAll('tspan') tspan = text.selectAll('tspan')
.data(function (d, i) { .data(function (d, i) {
...@@ -6902,9 +6908,9 @@ ...@@ -6902,9 +6908,9 @@
tspan.enter().append('tspan'); tspan.enter().append('tspan');
tspan.exit().remove(); tspan.exit().remove();
tspan.text(function (d) { return d.splitted; }); tspan.text(function (d) { return d.splitted; });
var rotate = params.tickTextRotate; var rotate = params.tickTextRotate;
function textAnchorForText(rotate) { function textAnchorForText(rotate) {
if (!rotate) { if (!rotate) {
return 'middle'; return 'middle';
...@@ -6929,7 +6935,7 @@ ...@@ -6929,7 +6935,7 @@
} }
return 11.5 - 2.5 * (rotate / 15) * (rotate > 0 ? 1 : -1); return 11.5 - 2.5 * (rotate / 15) * (rotate > 0 ? 1 : -1);
} }
switch (orient) { switch (orient) {
case "bottom": case "bottom":
{ {
...@@ -7067,7 +7073,7 @@ ...@@ -7067,7 +7073,7 @@
// PhantomJS doesn't have support for Function.prototype.bind, which has caused confusion. Use // PhantomJS doesn't have support for Function.prototype.bind, which has caused confusion. Use
// this polyfill to avoid the confusion. // this polyfill to avoid the confusion.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
if (!Function.prototype.bind) { if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) { Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') { if (typeof this !== 'function') {
...@@ -7075,17 +7081,17 @@ ...@@ -7075,17 +7081,17 @@
// internal IsCallable function // internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
} }
var aArgs = Array.prototype.slice.call(arguments, 1), var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this, fToBind = this,
fNOP = function() {}, fNOP = function() {},
fBound = function() { fBound = function() {
return fToBind.apply(this instanceof fNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); return fToBind.apply(this instanceof fNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
}; };
fNOP.prototype = this.prototype; fNOP.prototype = this.prototype;
fBound.prototype = new fNOP(); fBound.prototype = new fNOP();
return fBound; return fBound;
}; };
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -29,11 +29,11 @@ c3_chart_fn.tooltip.show = function (args) { ...@@ -29,11 +29,11 @@ c3_chart_fn.tooltip.show = function (args) {
$$.dispatchEvent('mouseover', index, mouse); $$.dispatchEvent('mouseover', index, mouse);
$$.dispatchEvent('mousemove', index, mouse); $$.dispatchEvent('mousemove', index, mouse);
config.tooltip_onshow.call($$, dataToShow); this.config.tooltip_onshow.call($$, args.data);
}; };
c3_chart_fn.tooltip.hide = function () { c3_chart_fn.tooltip.hide = function () {
// TODO: get target data by checking the state of focus // TODO: get target data by checking the state of focus
this.internal.dispatchEvent('mouseout', 0); this.internal.dispatchEvent('mouseout', 0);
config.tooltip_onhide.call(this); this.config.tooltip_onhide.call(this);
}; };
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