(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3')) : typeof define === 'function' && define.amd ? define(['exports', 'd3'], factory) : (factory((global.c3 = global.c3 || {}),global.d3)); }(this, (function (exports,d3) { 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; var set = function set(object, property, value, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent !== null) { set(parent, property, value, receiver); } } else if ("value" in desc && desc.writable) { desc.value = value; } else { var setter = desc.set; if (setter !== undefined) { setter.call(receiver, value); } } return value; }; function API(owner) { this.owner = owner; } function inherit(base, derived) { if (Object.create) { derived.prototype = Object.create(base.prototype); } else { var f = function f() {}; f.prototype = base.prototype; derived.prototype = new f(); } derived.prototype.constructor = derived; return derived; } // Features: // 1. category axis // 2. ceil values of translate/x/y to int for half pixel antialiasing // 3. multiline tick text var tickTextCharSize; function c3_axis(d3$$1, params) { var scale = d3$$1.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize, tickPadding = 3, tickValues = null, tickFormat, tickArguments; var tickOffset = 0, tickCulling = true, tickCentered; params = params || {}; outerTickSize = params.withOuterTick ? 6 : 0; function axisX(selection, x) { selection.attr("transform", function (d) { return "translate(" + Math.ceil(x(d) + tickOffset) + ", 0)"; }); } function axisY(selection, y) { selection.attr("transform", function (d) { return "translate(0," + Math.ceil(y(d)) + ")"; }); } function scaleExtent(domain) { var start = domain[0], stop = domain[domain.length - 1]; return start < stop ? [start, stop] : [stop, start]; } function generateTicks(scale) { var i, domain, ticks = []; if (scale.ticks) { return scale.ticks.apply(scale, tickArguments); } domain = scale.domain(); for (i = Math.ceil(domain[0]); i < domain[1]; i++) { ticks.push(i); } if (ticks.length > 0 && ticks[0] > 0) { ticks.unshift(ticks[0] - (ticks[1] - ticks[0])); } return ticks; } function copyScale() { var newScale = scale.copy(), domain; if (params.isCategory) { domain = scale.domain(); newScale.domain([domain[0], domain[1] - 1]); } return newScale; } function textFormatted(v) { var formatted = tickFormat ? tickFormat(v) : v; return typeof formatted !== 'undefined' ? formatted : ''; } function getSizeFor1Char(tick) { if (tickTextCharSize) { return tickTextCharSize; } var size = { h: 11.5, w: 5.5 }; tick.select('text').text(textFormatted).each(function (d) { var box = this.getBoundingClientRect(), text = textFormatted(d), h = box.height, w = text ? box.width / text.length : undefined; if (h && w) { size.h = h; size.w = w; } }).text(''); tickTextCharSize = size; return size; } function transitionise(selection) { return params.withoutTransition ? selection : d3$$1.transition(selection); } function axis(g) { g.each(function () { var g = axis.g = d3$$1.select(this); var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = copyScale(); var ticks = tickValues ? tickValues : generateTicks(scale1), tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", 1e-6), // MEMO: No exit transition. The reason is this transition affects max tick width calculation because old tick will be included in the ticks. tickExit = tick.exit().remove(), tickUpdate = transitionise(tick).style("opacity", 1), tickTransform, tickX, tickY; var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()), path = g.selectAll(".domain").data([0]), pathUpdate = (path.enter().append("path").attr("class", "domain"), transitionise(path)); tickEnter.append("line"); tickEnter.append("text"); var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"); if (params.isCategory) { tickOffset = Math.ceil((scale1(1) - scale1(0)) / 2); tickX = tickCentered ? 0 : tickOffset; tickY = tickCentered ? tickOffset : 0; } else { tickOffset = tickX = 0; } var text, tspan, sizeFor1Char = getSizeFor1Char(g.select('.tick')), counts = []; var tickLength = Math.max(innerTickSize, 0) + tickPadding, isVertical = orient === 'left' || orient === 'right'; // this should be called only when category axis function splitTickText(d, maxWidth) { var tickText = textFormatted(d), subtext, spaceIndex, textWidth, splitted = []; if (Object.prototype.toString.call(tickText) === "[object Array]") { return tickText; } if (!maxWidth || maxWidth <= 0) { maxWidth = isVertical ? 95 : params.isCategory ? Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 12 : 110; } function split(splitted, text) { spaceIndex = undefined; for (var i = 1; i < text.length; i++) { if (text.charAt(i) === ' ') { spaceIndex = i; } subtext = text.substr(0, i + 1); textWidth = sizeFor1Char.w * subtext.length; // if text width gets over tick width, split by space index or crrent index if (maxWidth < textWidth) { return split(splitted.concat(text.substr(0, spaceIndex ? spaceIndex : i)), text.slice(spaceIndex ? spaceIndex + 1 : i)); } } return splitted.concat(text); } return split(splitted, tickText + ""); } function tspanDy(d, i) { var dy = sizeFor1Char.h; if (i === 0) { if (orient === 'left' || orient === 'right') { dy = -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - 3); } else { dy = ".71em"; } } return dy; } function tickSize(d) { var tickPosition = scale(d) + (tickCentered ? 0 : tickOffset); return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0; } text = tick.select("text"); tspan = text.selectAll('tspan').data(function (d, i) { var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d)); counts[i] = splitted.length; return splitted.map(function (s) { return { index: i, splitted: s }; }); }); tspan.enter().append('tspan'); tspan.exit().remove(); tspan.text(function (d) { return d.splitted; }); var rotate = params.tickTextRotate; function textAnchorForText(rotate) { if (!rotate) { return 'middle'; } return rotate > 0 ? "start" : "end"; } function textTransform(rotate) { if (!rotate) { return ''; } return "rotate(" + rotate + ")"; } function dxForText(rotate) { if (!rotate) { return 0; } return 8 * Math.sin(Math.PI * (rotate / 180)); } function yForText(rotate) { if (!rotate) { return tickLength; } return 11.5 - 2.5 * (rotate / 15) * (rotate > 0 ? 1 : -1); } switch (orient) { case "bottom": { tickTransform = axisX; lineEnter.attr("y2", innerTickSize); textEnter.attr("y", tickLength); lineUpdate.attr("x1", tickX).attr("x2", tickX).attr("y2", tickSize); textUpdate.attr("x", 0).attr("y", yForText(rotate)).style("text-anchor", textAnchorForText(rotate)).attr("transform", textTransform(rotate)); tspan.attr('x', 0).attr("dy", tspanDy).attr('dx', dxForText(rotate)); pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize); break; } case "top": { // TODO: rotated tick text tickTransform = axisX; lineEnter.attr("y2", -innerTickSize); textEnter.attr("y", -tickLength); lineUpdate.attr("x2", 0).attr("y2", -innerTickSize); textUpdate.attr("x", 0).attr("y", -tickLength); text.style("text-anchor", "middle"); tspan.attr('x', 0).attr("dy", "0em"); pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize); break; } case "left": { tickTransform = axisY; lineEnter.attr("x2", -innerTickSize); textEnter.attr("x", -tickLength); lineUpdate.attr("x2", -innerTickSize).attr("y1", tickY).attr("y2", tickY); textUpdate.attr("x", -tickLength).attr("y", tickOffset); text.style("text-anchor", "end"); tspan.attr('x', -tickLength).attr("dy", tspanDy); pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize); break; } case "right": { tickTransform = axisY; lineEnter.attr("x2", innerTickSize); textEnter.attr("x", tickLength); lineUpdate.attr("x2", innerTickSize).attr("y2", 0); textUpdate.attr("x", tickLength).attr("y", 0); text.style("text-anchor", "start"); tspan.attr('x', tickLength).attr("dy", tspanDy); pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize); break; } } if (scale1.rangeBand) { var x = scale1, dx = x.rangeBand() / 2; scale0 = scale1 = function scale1(d) { return x(d) + dx; }; } else if (scale0.rangeBand) { scale0 = scale1; } else { tickExit.call(tickTransform, scale1); } tickEnter.call(tickTransform, scale0); tickUpdate.call(tickTransform, scale1); }); } axis.scale = function (x) { if (!arguments.length) { return scale; } scale = x; return axis; }; axis.orient = function (x) { if (!arguments.length) { return orient; } orient = x in { top: 1, right: 1, bottom: 1, left: 1 } ? x + "" : "bottom"; return axis; }; axis.tickFormat = function (format) { if (!arguments.length) { return tickFormat; } tickFormat = format; return axis; }; axis.tickCentered = function (isCentered) { if (!arguments.length) { return tickCentered; } tickCentered = isCentered; return axis; }; axis.tickOffset = function () { return tickOffset; }; axis.tickInterval = function () { var interval, length; if (params.isCategory) { interval = tickOffset * 2; } else { length = axis.g.select('path.domain').node().getTotalLength() - outerTickSize * 2; interval = length / axis.g.selectAll('line').size(); } return interval === Infinity ? 0 : interval; }; axis.ticks = function () { if (!arguments.length) { return tickArguments; } tickArguments = arguments; return axis; }; axis.tickCulling = function (culling) { if (!arguments.length) { return tickCulling; } tickCulling = culling; return axis; }; axis.tickValues = function (x) { if (typeof x === 'function') { tickValues = function tickValues() { return x(scale.domain()); }; } else { if (!arguments.length) { return tickValues; } tickValues = x; } return axis; }; return axis; } function Axis(owner) { API.call(this, owner); } inherit(API, Axis); Axis.prototype.init = function init() { var $$ = this.owner, config = $$.config, main = $$.main; $$.axes.x = main.append("g").attr("class", CLASS.axis + ' ' + CLASS.axisX).attr("clip-path", $$.clipPathForXAxis).attr("transform", $$.getTranslate('x')).style("visibility", config.axis_x_show ? 'visible' : 'hidden'); $$.axes.x.append("text").attr("class", CLASS.axisXLabel).attr("transform", config.axis_rotated ? "rotate(-90)" : "").style("text-anchor", this.textAnchorForXAxisLabel.bind(this)); $$.axes.y = main.append("g").attr("class", CLASS.axis + ' ' + CLASS.axisY).attr("clip-path", config.axis_y_inner ? "" : $$.clipPathForYAxis).attr("transform", $$.getTranslate('y')).style("visibility", config.axis_y_show ? 'visible' : 'hidden'); $$.axes.y.append("text").attr("class", CLASS.axisYLabel).attr("transform", config.axis_rotated ? "" : "rotate(-90)").style("text-anchor", this.textAnchorForYAxisLabel.bind(this)); $$.axes.y2 = main.append("g").attr("class", CLASS.axis + ' ' + CLASS.axisY2) // clip-path? .attr("transform", $$.getTranslate('y2')).style("visibility", config.axis_y2_show ? 'visible' : 'hidden'); $$.axes.y2.append("text").attr("class", CLASS.axisY2Label).attr("transform", config.axis_rotated ? "" : "rotate(-90)").style("text-anchor", this.textAnchorForY2AxisLabel.bind(this)); }; Axis.prototype.getXAxis = function getXAxis(scale, orient, tickFormat, tickValues, withOuterTick, withoutTransition, withoutRotateTickText) { var $$ = this.owner, config = $$.config, axisParams = { isCategory: $$.isCategorized(), withOuterTick: withOuterTick, tickMultiline: config.axis_x_tick_multiline, tickWidth: config.axis_x_tick_width, tickTextRotate: withoutRotateTickText ? 0 : config.axis_x_tick_rotate, withoutTransition: withoutTransition }, axis = c3_axis($$.d3, axisParams).scale(scale).orient(orient); if ($$.isTimeSeries() && tickValues && typeof tickValues !== "function") { tickValues = tickValues.map(function (v) { return $$.parseDate(v); }); } // Set tick axis.tickFormat(tickFormat).tickValues(tickValues); if ($$.isCategorized()) { axis.tickCentered(config.axis_x_tick_centered); if (isEmpty(config.axis_x_tick_culling)) { config.axis_x_tick_culling = false; } } return axis; }; Axis.prototype.updateXAxisTickValues = function updateXAxisTickValues(targets, axis) { var $$ = this.owner, config = $$.config, tickValues; if (config.axis_x_tick_fit || config.axis_x_tick_count) { tickValues = this.generateTickValues($$.mapTargetsToUniqueXs(targets), config.axis_x_tick_count, $$.isTimeSeries()); } if (axis) { axis.tickValues(tickValues); } else { $$.xAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues); } return tickValues; }; Axis.prototype.getYAxis = function getYAxis(scale, orient, tickFormat, tickValues, withOuterTick, withoutTransition, withoutRotateTickText) { var $$ = this.owner, config = $$.config, axisParams = { withOuterTick: withOuterTick, withoutTransition: withoutTransition, tickTextRotate: withoutRotateTickText ? 0 : config.axis_y_tick_rotate }, axis = c3_axis($$.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat); if ($$.isTimeSeriesY()) { axis.ticks($$.d3.time[config.axis_y_tick_time_value], config.axis_y_tick_time_interval); } else { axis.tickValues(tickValues); } return axis; }; Axis.prototype.getId = function getId(id) { var config = this.owner.config; return id in config.data_axes ? config.data_axes[id] : 'y'; }; Axis.prototype.getXAxisTickFormat = function getXAxisTickFormat() { var $$ = this.owner, config = $$.config, format = $$.isTimeSeries() ? $$.defaultAxisTimeFormat : $$.isCategorized() ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; if (config.axis_x_tick_format) { if (isFunction(config.axis_x_tick_format)) { format = config.axis_x_tick_format; } else if ($$.isTimeSeries()) { format = function format(date) { return date ? $$.axisTimeFormat(config.axis_x_tick_format)(date) : ""; }; } } return isFunction(format) ? function (v) { return format.call($$, v); } : format; }; Axis.prototype.getTickValues = function getTickValues(tickValues, axis) { return tickValues ? tickValues : axis ? axis.tickValues() : undefined; }; Axis.prototype.getXAxisTickValues = function getXAxisTickValues() { return this.getTickValues(this.owner.config.axis_x_tick_values, this.owner.xAxis); }; Axis.prototype.getYAxisTickValues = function getYAxisTickValues() { return this.getTickValues(this.owner.config.axis_y_tick_values, this.owner.yAxis); }; Axis.prototype.getY2AxisTickValues = function getY2AxisTickValues() { return this.getTickValues(this.owner.config.axis_y2_tick_values, this.owner.y2Axis); }; Axis.prototype.getLabelOptionByAxisId = function getLabelOptionByAxisId(axisId) { var $$ = this.owner, config = $$.config, option; if (axisId === 'y') { option = config.axis_y_label; } else if (axisId === 'y2') { option = config.axis_y2_label; } else if (axisId === 'x') { option = config.axis_x_label; } return option; }; Axis.prototype.getLabelText = function getLabelText(axisId) { var option = this.getLabelOptionByAxisId(axisId); return isString(option) ? option : option ? option.text : null; }; Axis.prototype.setLabelText = function setLabelText(axisId, text) { var $$ = this.owner, config = $$.config, option = this.getLabelOptionByAxisId(axisId); if (isString(option)) { if (axisId === 'y') { config.axis_y_label = text; } else if (axisId === 'y2') { config.axis_y2_label = text; } else if (axisId === 'x') { config.axis_x_label = text; } } else if (option) { option.text = text; } }; Axis.prototype.getLabelPosition = function getLabelPosition(axisId, defaultPosition) { var option = this.getLabelOptionByAxisId(axisId), position = option && (typeof option === "undefined" ? "undefined" : _typeof(option)) === 'object' && option.position ? option.position : defaultPosition; return { isInner: position.indexOf('inner') >= 0, isOuter: position.indexOf('outer') >= 0, isLeft: position.indexOf('left') >= 0, isCenter: position.indexOf('center') >= 0, isRight: position.indexOf('right') >= 0, isTop: position.indexOf('top') >= 0, isMiddle: position.indexOf('middle') >= 0, isBottom: position.indexOf('bottom') >= 0 }; }; Axis.prototype.getXAxisLabelPosition = function getXAxisLabelPosition() { return this.getLabelPosition('x', this.owner.config.axis_rotated ? 'inner-top' : 'inner-right'); }; Axis.prototype.getYAxisLabelPosition = function getYAxisLabelPosition() { return this.getLabelPosition('y', this.owner.config.axis_rotated ? 'inner-right' : 'inner-top'); }; Axis.prototype.getY2AxisLabelPosition = function getY2AxisLabelPosition() { return this.getLabelPosition('y2', this.owner.config.axis_rotated ? 'inner-right' : 'inner-top'); }; Axis.prototype.getLabelPositionById = function getLabelPositionById(id) { return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); }; Axis.prototype.textForXAxisLabel = function textForXAxisLabel() { return this.getLabelText('x'); }; Axis.prototype.textForYAxisLabel = function textForYAxisLabel() { return this.getLabelText('y'); }; Axis.prototype.textForY2AxisLabel = function textForY2AxisLabel() { return this.getLabelText('y2'); }; Axis.prototype.xForAxisLabel = function xForAxisLabel(forHorizontal, position) { var $$ = this.owner; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; } else { return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; Axis.prototype.dxForAxisLabel = function dxForAxisLabel(forHorizontal, position) { if (forHorizontal) { return position.isLeft ? "0.5em" : position.isRight ? "-0.5em" : "0"; } else { return position.isTop ? "-0.5em" : position.isBottom ? "0.5em" : "0"; } }; Axis.prototype.textAnchorForAxisLabel = function textAnchorForAxisLabel(forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; Axis.prototype.xForXAxisLabel = function xForXAxisLabel() { return this.xForAxisLabel(!this.owner.config.axis_rotated, this.getXAxisLabelPosition()); }; Axis.prototype.xForYAxisLabel = function xForYAxisLabel() { return this.xForAxisLabel(this.owner.config.axis_rotated, this.getYAxisLabelPosition()); }; Axis.prototype.xForY2AxisLabel = function xForY2AxisLabel() { return this.xForAxisLabel(this.owner.config.axis_rotated, this.getY2AxisLabelPosition()); }; Axis.prototype.dxForXAxisLabel = function dxForXAxisLabel() { return this.dxForAxisLabel(!this.owner.config.axis_rotated, this.getXAxisLabelPosition()); }; Axis.prototype.dxForYAxisLabel = function dxForYAxisLabel() { return this.dxForAxisLabel(this.owner.config.axis_rotated, this.getYAxisLabelPosition()); }; Axis.prototype.dxForY2AxisLabel = function dxForY2AxisLabel() { return this.dxForAxisLabel(this.owner.config.axis_rotated, this.getY2AxisLabelPosition()); }; Axis.prototype.dyForXAxisLabel = function dyForXAxisLabel() { var $$ = this.owner, config = $$.config, position = this.getXAxisLabelPosition(); if (config.axis_rotated) { return position.isInner ? "1.2em" : -25 - this.getMaxTickWidth('x'); } else { return position.isInner ? "-0.5em" : config.axis_x_height ? config.axis_x_height - 10 : "3em"; } }; Axis.prototype.dyForYAxisLabel = function dyForYAxisLabel() { var $$ = this.owner, position = this.getYAxisLabelPosition(); if ($$.config.axis_rotated) { return position.isInner ? "-0.5em" : "3em"; } else { return position.isInner ? "1.2em" : -10 - ($$.config.axis_y_inner ? 0 : this.getMaxTickWidth('y') + 10); } }; Axis.prototype.dyForY2AxisLabel = function dyForY2AxisLabel() { var $$ = this.owner, position = this.getY2AxisLabelPosition(); if ($$.config.axis_rotated) { return position.isInner ? "1.2em" : "-2.2em"; } else { return position.isInner ? "-0.5em" : 15 + ($$.config.axis_y2_inner ? 0 : this.getMaxTickWidth('y2') + 15); } }; Axis.prototype.textAnchorForXAxisLabel = function textAnchorForXAxisLabel() { var $$ = this.owner; return this.textAnchorForAxisLabel(!$$.config.axis_rotated, this.getXAxisLabelPosition()); }; Axis.prototype.textAnchorForYAxisLabel = function textAnchorForYAxisLabel() { var $$ = this.owner; return this.textAnchorForAxisLabel($$.config.axis_rotated, this.getYAxisLabelPosition()); }; Axis.prototype.textAnchorForY2AxisLabel = function textAnchorForY2AxisLabel() { var $$ = this.owner; return this.textAnchorForAxisLabel($$.config.axis_rotated, this.getY2AxisLabelPosition()); }; Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute) { var $$ = this.owner, config = $$.config, maxWidth = 0, targetsToShow, scale, axis, dummy, svg; if (withoutRecompute && $$.currentMaxTickWidths[id]) { return $$.currentMaxTickWidths[id]; } if ($$.svg) { targetsToShow = $$.filterTargetsToShow($$.data.targets); if (id === 'y') { scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); axis = this.getYAxis(scale, $$.yOrient, config.axis_y_tick_format, $$.yAxisTickValues, false, true, true); } else if (id === 'y2') { scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); axis = this.getYAxis(scale, $$.y2Orient, config.axis_y2_tick_format, $$.y2AxisTickValues, false, true, true); } else { scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); axis = this.getXAxis(scale, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, false, true, true); this.updateXAxisTickValues(targetsToShow, axis); } dummy = $$.d3.select('body').append('div').classed('c3', true); svg = dummy.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0), svg.append('g').call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { var box = this.getBoundingClientRect(); if (maxWidth < box.width) { maxWidth = box.width; } }); dummy.remove(); }); } $$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth; return $$.currentMaxTickWidths[id]; }; Axis.prototype.updateLabels = function updateLabels(withTransition) { var $$ = this.owner; var axisXLabel = $$.main.select('.' + CLASS.axisX + ' .' + CLASS.axisXLabel), axisYLabel = $$.main.select('.' + CLASS.axisY + ' .' + CLASS.axisYLabel), axisY2Label = $$.main.select('.' + CLASS.axisY2 + ' .' + CLASS.axisY2Label); (withTransition ? axisXLabel.transition() : axisXLabel).attr("x", this.xForXAxisLabel.bind(this)).attr("dx", this.dxForXAxisLabel.bind(this)).attr("dy", this.dyForXAxisLabel.bind(this)).text(this.textForXAxisLabel.bind(this)); (withTransition ? axisYLabel.transition() : axisYLabel).attr("x", this.xForYAxisLabel.bind(this)).attr("dx", this.dxForYAxisLabel.bind(this)).attr("dy", this.dyForYAxisLabel.bind(this)).text(this.textForYAxisLabel.bind(this)); (withTransition ? axisY2Label.transition() : axisY2Label).attr("x", this.xForY2AxisLabel.bind(this)).attr("dx", this.dxForY2AxisLabel.bind(this)).attr("dy", this.dyForY2AxisLabel.bind(this)).text(this.textForY2AxisLabel.bind(this)); }; Axis.prototype.getPadding = function getPadding(padding, key, defaultValue, domainLength) { var p = typeof padding === 'number' ? padding : padding[key]; if (!isValue(p)) { return defaultValue; } if (padding.unit === 'ratio') { return padding[key] * domainLength; } // assume padding is pixels if unit is not specified return this.convertPixelsToAxisPadding(p, domainLength); }; Axis.prototype.convertPixelsToAxisPadding = function convertPixelsToAxisPadding(pixels, domainLength) { var $$ = this.owner, length = $$.config.axis_rotated ? $$.width : $$.height; return domainLength * (pixels / length); }; Axis.prototype.generateTickValues = function generateTickValues(values, tickCount, forTimeSeries) { var tickValues = values, targetCount, start, end, count, interval, i, tickValue; if (tickCount) { targetCount = isFunction(tickCount) ? tickCount() : tickCount; // compute ticks according to tickCount if (targetCount === 1) { tickValues = [values[0]]; } else if (targetCount === 2) { tickValues = [values[0], values[values.length - 1]]; } else if (targetCount > 2) { count = targetCount - 2; start = values[0]; end = values[values.length - 1]; interval = (end - start) / (count + 1); // re-construct unique values tickValues = [start]; for (i = 0; i < count; i++) { tickValue = +start + interval * (i + 1); tickValues.push(forTimeSeries ? new Date(tickValue) : tickValue); } tickValues.push(end); } } if (!forTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } return tickValues; }; Axis.prototype.generateTransitions = function generateTransitions(duration) { var $$ = this.owner, axes = $$.axes; return { axisX: duration ? axes.x.transition().duration(duration) : axes.x, axisY: duration ? axes.y.transition().duration(duration) : axes.y, axisY2: duration ? axes.y2.transition().duration(duration) : axes.y2, axisSubX: duration ? axes.subx.transition().duration(duration) : axes.subx }; }; Axis.prototype.redraw = function redraw(transitions, isHidden) { var $$ = this.owner; $$.axes.x.style("opacity", isHidden ? 0 : 1); $$.axes.y.style("opacity", isHidden ? 0 : 1); $$.axes.y2.style("opacity", isHidden ? 0 : 1); $$.axes.subx.style("opacity", isHidden ? 0 : 1); transitions.axisX.call($$.xAxis); transitions.axisY.call($$.yAxis); transitions.axisY2.call($$.y2Axis); transitions.axisSubX.call($$.subXAxis); }; function ChartInternal(api){var $$=this;$$.d3=window.d3?window.d3:typeof require!=='undefined'?require("d3"):undefined;$$.api=api;$$.config=$$.getDefaultConfig();$$.data={};$$.cache={};$$.axes={};}var c3_chart_internal_fn=ChartInternal.prototype;c3_chart_internal_fn.beforeInit=function(){// can do something };c3_chart_internal_fn.afterInit=function(){// can do something };c3_chart_internal_fn.init=function(){var $$=this,config=$$.config;$$.initParams();if(config.data_url){$$.convertUrlToData(config.data_url,config.data_mimeType,config.data_headers,config.data_keys,$$.initWithData);}else if(config.data_json){$$.initWithData($$.convertJsonToData(config.data_json,config.data_keys));}else if(config.data_rows){$$.initWithData($$.convertRowsToData(config.data_rows));}else if(config.data_columns){$$.initWithData($$.convertColumnsToData(config.data_columns));}else{throw Error('url or json or rows or columns is required.');}};c3_chart_internal_fn.initParams=function(){var $$=this,d3$$1=$$.d3,config=$$.config;// MEMO: clipId needs to be unique because it conflicts when multiple charts exist $$.clipId="c3-"+ +new Date()+'-clip',$$.clipIdForXAxis=$$.clipId+'-xaxis',$$.clipIdForYAxis=$$.clipId+'-yaxis',$$.clipIdForGrid=$$.clipId+'-grid',$$.clipIdForSubchart=$$.clipId+'-subchart',$$.clipPath=$$.getClipPath($$.clipId),$$.clipPathForXAxis=$$.getClipPath($$.clipIdForXAxis),$$.clipPathForYAxis=$$.getClipPath($$.clipIdForYAxis);$$.clipPathForGrid=$$.getClipPath($$.clipIdForGrid),$$.clipPathForSubchart=$$.getClipPath($$.clipIdForSubchart),$$.dragStart=null;$$.dragging=false;$$.flowing=false;$$.cancelClick=false;$$.mouseover=false;$$.transiting=false;$$.color=$$.generateColor();$$.levelColor=$$.generateLevelColor();$$.dataTimeFormat=config.data_xLocaltime?d3$$1.time.format:d3$$1.time.format.utc;$$.axisTimeFormat=config.axis_x_localtime?d3$$1.time.format:d3$$1.time.format.utc;$$.defaultAxisTimeFormat=$$.axisTimeFormat.multi([[".%L",function(d){return d.getMilliseconds();}],[":%S",function(d){return d.getSeconds();}],["%I:%M",function(d){return d.getMinutes();}],["%I %p",function(d){return d.getHours();}],["%-m/%-d",function(d){return d.getDay()&&d.getDate()!==1;}],["%-m/%-d",function(d){return d.getDate()!==1;}],["%-m/%-d",function(d){return d.getMonth();}],["%Y/%-m/%-d",function(){return true;}]]);$$.hiddenTargetIds=[];$$.hiddenLegendIds=[];$$.focusedTargetIds=[];$$.defocusedTargetIds=[];$$.xOrient=config.axis_rotated?"left":"bottom";$$.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";$$.subXOrient=config.axis_rotated?"left":"bottom";$$.isLegendRight=config.legend_position==='right';$$.isLegendInset=config.legend_position==='inset';$$.isLegendTop=config.legend_inset_anchor==='top-left'||config.legend_inset_anchor==='top-right';$$.isLegendLeft=config.legend_inset_anchor==='top-left'||config.legend_inset_anchor==='bottom-left';$$.legendStep=0;$$.legendItemWidth=0;$$.legendItemHeight=0;$$.currentMaxTickWidths={x:0,y:0,y2:0};$$.rotated_padding_left=30;$$.rotated_padding_right=config.axis_rotated&&!config.axis_x_show?0:30;$$.rotated_padding_top=5;$$.withoutFadeIn={};$$.intervalForObserveInserted=undefined;$$.axes.subx=d3$$1.selectAll([]);// needs when excluding subchart.js };c3_chart_internal_fn.initChartElements=function(){if(this.initBar){this.initBar();}if(this.initLine){this.initLine();}if(this.initArc){this.initArc();}if(this.initGauge){this.initGauge();}if(this.initText){this.initText();}};c3_chart_internal_fn.initWithData=function(data){var $$=this,d3$$1=$$.d3,config=$$.config;var defs,main,binding=true;$$.axis=new Axis($$);if($$.initPie){$$.initPie();}if($$.initBrush){$$.initBrush();}if($$.initZoom){$$.initZoom();}if(!config.bindto){$$.selectChart=d3$$1.selectAll([]);}else if(typeof config.bindto.node==='function'){$$.selectChart=config.bindto;}else{$$.selectChart=d3$$1.select(config.bindto);}if($$.selectChart.empty()){$$.selectChart=d3$$1.select(document.createElement('div')).style('opacity',0);$$.observeInserted($$.selectChart);binding=false;}$$.selectChart.html("").classed("c3",true);// Init data as targets $$.data.xs={};$$.data.targets=$$.convertDataToTargets(data);if(config.data_filter){$$.data.targets=$$.data.targets.filter(config.data_filter);}// Set targets to hide if needed if(config.data_hide){$$.addHiddenTargetIds(config.data_hide===true?$$.mapToIds($$.data.targets):config.data_hide);}if(config.legend_hide){$$.addHiddenLegendIds(config.legend_hide===true?$$.mapToIds($$.data.targets):config.legend_hide);}// when gauge, hide legend // TODO: fix if($$.hasType('gauge')){config.legend_show=false;}// Init sizes and scales $$.updateSizes();$$.updateScales();// Set domains for each scale $$.x.domain(d3$$1.extent($$.getXDomain($$.data.targets)));$$.y.domain($$.getYDomain($$.data.targets,'y'));$$.y2.domain($$.getYDomain($$.data.targets,'y2'));$$.subX.domain($$.x.domain());$$.subY.domain($$.y.domain());$$.subY2.domain($$.y2.domain());// Save original x domain for zoom update $$.orgXDomain=$$.x.domain();// Set initialized scales to brush and zoom if($$.brush){$$.brush.scale($$.subX);}if(config.zoom_enabled){$$.zoom.scale($$.x);}/*-- Basic Elements --*/// Define svgs $$.svg=$$.selectChart.append("svg").style("overflow","hidden").on('mouseenter',function(){return config.onmouseover.call($$);}).on('mouseleave',function(){return config.onmouseout.call($$);});if($$.config.svg_classname){$$.svg.attr('class',$$.config.svg_classname);}// Define defs defs=$$.svg.append("defs");$$.clipChart=$$.appendClip(defs,$$.clipId);$$.clipXAxis=$$.appendClip(defs,$$.clipIdForXAxis);$$.clipYAxis=$$.appendClip(defs,$$.clipIdForYAxis);$$.clipGrid=$$.appendClip(defs,$$.clipIdForGrid);$$.clipSubchart=$$.appendClip(defs,$$.clipIdForSubchart);$$.updateSvgSize();// Define regions main=$$.main=$$.svg.append("g").attr("transform",$$.getTranslate('main'));if($$.initSubchart){$$.initSubchart();}if($$.initTooltip){$$.initTooltip();}if($$.initLegend){$$.initLegend();}if($$.initTitle){$$.initTitle();}/*-- Main Region --*/// text when empty main.append("text").attr("class",CLASS.text+' '+CLASS.empty).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. // Regions $$.initRegion();// Grids $$.initGrid();// Define g for chart area main.append('g').attr("clip-path",$$.clipPath).attr('class',CLASS.chart);// Grid lines if(config.grid_lines_front){$$.initGridLines();}// Cover whole with rects for events $$.initEventRect();// Define g for chart $$.initChartElements();// if zoom privileged, insert rect to forefront // TODO: is this needed? main.insert('rect',config.zoom_privileged?null:'g.'+CLASS.regions).attr('class',CLASS.zoomRect).attr('width',$$.width).attr('height',$$.height).style('opacity',0).on("dblclick.zoom",null);// Set default extent if defined if(config.axis_x_extent){$$.brush.extent($$.getDefaultExtent());}// Add Axis $$.axis.init();// Set targets $$.updateTargets($$.data.targets);// Draw with targets if(binding){$$.updateDimension();$$.config.oninit.call($$);$$.redraw({withTransition:false,withTransform:true,withUpdateXDomain:true,withUpdateOrgXDomain:true,withTransitionForAxis:false});}// Bind resize event $$.bindResize();// export element of the chart $$.api.element=$$.selectChart.node();};c3_chart_internal_fn.smoothLines=function(el,type){var $$=this;if(type==='grid'){el.each(function(){var g=$$.d3.select(this),x1=g.attr('x1'),x2=g.attr('x2'),y1=g.attr('y1'),y2=g.attr('y2');g.attr({'x1':Math.ceil(x1),'x2':Math.ceil(x2),'y1':Math.ceil(y1),'y2':Math.ceil(y2)});});}};c3_chart_internal_fn.updateSizes=function(){var $$=this,config=$$.config;var legendHeight=$$.legend?$$.getLegendHeight():0,legendWidth=$$.legend?$$.getLegendWidth():0,legendHeightForBottom=$$.isLegendRight||$$.isLegendInset?0:legendHeight,hasArc=$$.hasArcType(),xAxisHeight=config.axis_rotated||hasArc?0:$$.getHorizontalAxisHeight('x'),subchartHeight=config.subchart_show&&!hasArc?config.subchart_size_height+xAxisHeight:0;$$.currentWidth=$$.getCurrentWidth();$$.currentHeight=$$.getCurrentHeight();// for main $$.margin=config.axis_rotated?{top:$$.getHorizontalAxisHeight('y2')+$$.getCurrentPaddingTop(),right:hasArc?0:$$.getCurrentPaddingRight(),bottom:$$.getHorizontalAxisHeight('y')+legendHeightForBottom+$$.getCurrentPaddingBottom(),left:subchartHeight+(hasArc?0:$$.getCurrentPaddingLeft())}:{top:4+$$.getCurrentPaddingTop(),// for top tick text right:hasArc?0:$$.getCurrentPaddingRight(),bottom:xAxisHeight+subchartHeight+legendHeightForBottom+$$.getCurrentPaddingBottom(),left:hasArc?0:$$.getCurrentPaddingLeft()};// for subchart $$.margin2=config.axis_rotated?{top:$$.margin.top,right:NaN,bottom:20+legendHeightForBottom,left:$$.rotated_padding_left}:{top:$$.currentHeight-subchartHeight-legendHeightForBottom,right:NaN,bottom:xAxisHeight+legendHeightForBottom,left:$$.margin.left};// for legend $$.margin3={top:0,right:NaN,bottom:0,left:0};if($$.updateSizeForLegend){$$.updateSizeForLegend(legendHeight,legendWidth);}$$.width=$$.currentWidth-$$.margin.left-$$.margin.right;$$.height=$$.currentHeight-$$.margin.top-$$.margin.bottom;if($$.width<0){$$.width=0;}if($$.height<0){$$.height=0;}$$.width2=config.axis_rotated?$$.margin.left-$$.rotated_padding_left-$$.rotated_padding_right:$$.width;$$.height2=config.axis_rotated?$$.height:$$.currentHeight-$$.margin2.top-$$.margin2.bottom;if($$.width2<0){$$.width2=0;}if($$.height2<0){$$.height2=0;}// for arc $$.arcWidth=$$.width-($$.isLegendRight?legendWidth+10:0);$$.arcHeight=$$.height-($$.isLegendRight?0:10);if($$.hasType('gauge')&&!config.gauge_fullCircle){$$.arcHeight+=$$.height-$$.getGaugeLabelHeight();}if($$.updateRadius){$$.updateRadius();}if($$.isLegendRight&&hasArc){$$.margin3.left=$$.arcWidth/2+$$.radiusExpanded*1.1;}};c3_chart_internal_fn.updateTargets=function(targets){var $$=this;/*-- Main --*///-- Text --// $$.updateTargetsForText(targets);//-- Bar --// $$.updateTargetsForBar(targets);//-- Line --// $$.updateTargetsForLine(targets);//-- Arc --// if($$.hasArcType()&&$$.updateTargetsForArc){$$.updateTargetsForArc(targets);}/*-- Sub --*/if($$.updateTargetsForSubchart){$$.updateTargetsForSubchart(targets);}// Fade-in each chart $$.showTargets();};c3_chart_internal_fn.showTargets=function(){var $$=this;$$.svg.selectAll('.'+CLASS.target).filter(function(d){return $$.isTargetToShow(d.id);}).transition().duration($$.config.transition_duration).style("opacity",1);};c3_chart_internal_fn.redraw=function(options,transitions){var $$=this,main=$$.main,d3$$1=$$.d3,config=$$.config;var areaIndices=$$.getShapeIndices($$.isAreaType),barIndices=$$.getShapeIndices($$.isBarType),lineIndices=$$.getShapeIndices($$.isLineType);var withY,withSubchart,withTransition,withTransitionForExit,withTransitionForAxis,withTransform,withUpdateXDomain,withUpdateOrgXDomain,withTrimXDomain,withLegend,withEventRect,withDimension,withUpdateXAxis;var hideAxis=$$.hasArcType();var drawArea,drawBar,drawLine,xForText,yForText;var duration,durationForExit,durationForAxis;var waitForDraw,flow;var targetsToShow=$$.filterTargetsToShow($$.data.targets),tickValues,i,intervalForCulling,xDomainForZoom;var xv=$$.xv.bind($$),cx,cy;options=options||{};withY=getOption(options,"withY",true);withSubchart=getOption(options,"withSubchart",true);withTransition=getOption(options,"withTransition",true);withTransform=getOption(options,"withTransform",false);withUpdateXDomain=getOption(options,"withUpdateXDomain",false);withUpdateOrgXDomain=getOption(options,"withUpdateOrgXDomain",false);withTrimXDomain=getOption(options,"withTrimXDomain",true);withUpdateXAxis=getOption(options,"withUpdateXAxis",withUpdateXDomain);withLegend=getOption(options,"withLegend",false);withEventRect=getOption(options,"withEventRect",true);withDimension=getOption(options,"withDimension",true);withTransitionForExit=getOption(options,"withTransitionForExit",withTransition);withTransitionForAxis=getOption(options,"withTransitionForAxis",withTransition);duration=withTransition?config.transition_duration:0;durationForExit=withTransitionForExit?duration:0;durationForAxis=withTransitionForAxis?duration:0;transitions=transitions||$$.axis.generateTransitions(durationForAxis);// update legend and transform each g if(withLegend&&config.legend_show){$$.updateLegend($$.mapToIds($$.data.targets),options,transitions);}else if(withDimension){// need to update dimension (e.g. axis.y.tick.values) because y tick values should change // no need to update axis in it because they will be updated in redraw() $$.updateDimension(true);}// MEMO: needed for grids calculation if($$.isCategorized()&&targetsToShow.length===0){$$.x.domain([0,$$.axes.x.selectAll('.tick').size()]);}if(targetsToShow.length){$$.updateXDomain(targetsToShow,withUpdateXDomain,withUpdateOrgXDomain,withTrimXDomain);if(!config.axis_x_tick_values){tickValues=$$.axis.updateXAxisTickValues(targetsToShow);}}else{$$.xAxis.tickValues([]);$$.subXAxis.tickValues([]);}if(config.zoom_rescale&&!options.flow){xDomainForZoom=$$.x.orgDomain();}$$.y.domain($$.getYDomain(targetsToShow,'y',xDomainForZoom));$$.y2.domain($$.getYDomain(targetsToShow,'y2',xDomainForZoom));if(!config.axis_y_tick_values&&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){$$.y2Axis.tickValues($$.axis.generateTickValues($$.y2.domain(),config.axis_y2_tick_count));}// axes $$.axis.redraw(transitions,hideAxis);// Update axis label $$.axis.updateLabels(withTransition);// show/hide if manual culling needed if((withUpdateXDomain||withUpdateXAxis)&&targetsToShow.length){if(config.axis_x_tick_culling&&tickValues){for(i=1;i=0){d3$$1.select(this).style('display',index%intervalForCulling?'none':'block');}});}else{$$.svg.selectAll('.'+CLASS.axisX+' .tick text').style('display','block');}}// setup drawer - MEMO: these must be called after axis updated drawArea=$$.generateDrawArea?$$.generateDrawArea(areaIndices,false):undefined;drawBar=$$.generateDrawBar?$$.generateDrawBar(barIndices):undefined;drawLine=$$.generateDrawLine?$$.generateDrawLine(lineIndices,false):undefined;xForText=$$.generateXYForText(areaIndices,barIndices,lineIndices,true);yForText=$$.generateXYForText(areaIndices,barIndices,lineIndices,false);// Update sub domain if(withY){$$.subY.domain($$.getYDomain(targetsToShow,'y'));$$.subY2.domain($$.getYDomain(targetsToShow,'y2'));}// xgrid focus $$.updateXgridFocus();// Data empty label positioning and text. main.select("text."+CLASS.text+'.'+CLASS.empty).attr("x",$$.width/2).attr("y",$$.height/2).text(config.data_empty_label_text).transition().style('opacity',targetsToShow.length?0:1);// grid $$.updateGrid(duration);// rect for regions $$.updateRegion(duration);// bars $$.updateBar(durationForExit);// lines, areas and cricles $$.updateLine(durationForExit);$$.updateArea(durationForExit);$$.updateCircle();// text if($$.hasDataLabel()){$$.updateText(durationForExit);}// title if($$.redrawTitle){$$.redrawTitle();}// arc if($$.redrawArc){$$.redrawArc(duration,durationForExit,withTransform);}// subchart if($$.redrawSubchart){$$.redrawSubchart(withSubchart,transitions,duration,durationForExit,areaIndices,barIndices,lineIndices);}// circles for select main.selectAll('.'+CLASS.selectedCircles).filter($$.isBarType.bind($$)).selectAll('circle').remove();// event rects will redrawn when flow called if(config.interaction_enabled&&!options.flow&&withEventRect){$$.redrawEventRect();if($$.updateZoom){$$.updateZoom();}}// update circleY based on updated parameters $$.updateCircleY();// generate circle x/y functions depending on updated params cx=($$.config.axis_rotated?$$.circleY:$$.circleX).bind($$);cy=($$.config.axis_rotated?$$.circleX:$$.circleY).bind($$);if(options.flow){flow=$$.generateFlow({targets:targetsToShow,flow:options.flow,duration:options.flow.duration,drawBar:drawBar,drawLine:drawLine,drawArea:drawArea,cx:cx,cy:cy,xv:xv,xForText:xForText,yForText:yForText});}if((duration||flow)&&$$.isTabVisible()){// Only use transition if tab visible. See #938. // transition should be derived from one transition d3$$1.transition().duration(duration).each(function(){var transitionsToWait=[];// redraw and gather transitions [$$.redrawBar(drawBar,true),$$.redrawLine(drawLine,true),$$.redrawArea(drawArea,true),$$.redrawCircle(cx,cy,true),$$.redrawText(xForText,yForText,options.flow,true),$$.redrawRegion(true),$$.redrawGrid(true)].forEach(function(transitions){transitions.forEach(function(transition){transitionsToWait.push(transition);});});// Wait for end of transitions to call flow and onrendered callback waitForDraw=$$.generateWait();transitionsToWait.forEach(function(t){waitForDraw.add(t);});}).call(waitForDraw,function(){if(flow){flow();}if(config.onrendered){config.onrendered.call($$);}});}else{$$.redrawBar(drawBar);$$.redrawLine(drawLine);$$.redrawArea(drawArea);$$.redrawCircle(cx,cy);$$.redrawText(xForText,yForText,options.flow);$$.redrawRegion();$$.redrawGrid();if(config.onrendered){config.onrendered.call($$);}}// update fadein condition $$.mapToIds($$.data.targets).forEach(function(id){$$.withoutFadeIn[id]=true;});};c3_chart_internal_fn.updateAndRedraw=function(options){var $$=this,config=$$.config,transitions;options=options||{};// same with redraw options.withTransition=getOption(options,"withTransition",true);options.withTransform=getOption(options,"withTransform",false);options.withLegend=getOption(options,"withLegend",false);// NOT same with redraw options.withUpdateXDomain=true;options.withUpdateOrgXDomain=true;options.withTransitionForExit=false;options.withTransitionForTransform=getOption(options,"withTransitionForTransform",options.withTransition);// MEMO: this needs to be called before updateLegend and it means this ALWAYS needs to be called) $$.updateSizes();// MEMO: called in updateLegend in redraw if withLegend if(!(options.withLegend&&config.legend_show)){transitions=$$.axis.generateTransitions(options.withTransitionForAxis?config.transition_duration:0);// Update scales $$.updateScales();$$.updateSvgSize();// Update g positions $$.transformAll(options.withTransitionForTransform,transitions);}// Draw with new sizes & scales $$.redraw(options,transitions);};c3_chart_internal_fn.redrawWithoutRescale=function(){this.redraw({withY:false,withSubchart:false,withEventRect:false,withTransitionForAxis:false});};c3_chart_internal_fn.isTimeSeries=function(){return this.config.axis_x_type==='timeseries';};c3_chart_internal_fn.isCategorized=function(){return this.config.axis_x_type.indexOf('categor')>=0;};c3_chart_internal_fn.isCustomX=function(){var $$=this,config=$$.config;return!$$.isTimeSeries()&&(config.data_x||notEmpty(config.data_xs));};c3_chart_internal_fn.isTimeSeriesY=function(){return this.config.axis_y_type==='timeseries';};c3_chart_internal_fn.getTranslate=function(target){var $$=this,config=$$.config,x,y;if(target==='main'){x=asHalfPixel($$.margin.left);y=asHalfPixel($$.margin.top);}else if(target==='context'){x=asHalfPixel($$.margin2.left);y=asHalfPixel($$.margin2.top);}else if(target==='legend'){x=$$.margin3.left;y=$$.margin3.top;}else if(target==='x'){x=0;y=config.axis_rotated?0:$$.height;}else if(target==='y'){x=0;y=config.axis_rotated?$$.height:0;}else if(target==='y2'){x=config.axis_rotated?0:$$.width;y=config.axis_rotated?1:0;}else if(target==='subx'){x=0;y=config.axis_rotated?0:$$.height2;}else if(target==='arc'){x=$$.arcWidth/2;y=$$.arcHeight/2;}return"translate("+x+","+y+")";};c3_chart_internal_fn.initialOpacity=function(d){return d.value!==null&&this.withoutFadeIn[d.id]?1:0;};c3_chart_internal_fn.initialOpacityForCircle=function(d){return d.value!==null&&this.withoutFadeIn[d.id]?this.opacityForCircle(d):0;};c3_chart_internal_fn.opacityForCircle=function(d){var opacity=this.config.point_show?1:0;return isValue(d.value)?this.isScatterType(d)?0.5:opacity:0;};c3_chart_internal_fn.opacityForText=function(){return this.hasDataLabel()?1:0;};c3_chart_internal_fn.xx=function(d){return d?this.x(d.x):null;};c3_chart_internal_fn.xv=function(d){var $$=this,value=d.value;if($$.isTimeSeries()){value=$$.parseDate(d.value);}else if($$.isCategorized()&&typeof d.value==='string'){value=$$.config.axis_x_categories.indexOf(d.value);}return Math.ceil($$.x(value));};c3_chart_internal_fn.yv=function(d){var $$=this,yScale=d.axis&&d.axis==='y2'?$$.y2:$$.y;return Math.ceil(yScale(d.value));};c3_chart_internal_fn.subxx=function(d){return d?this.subX(d.x):null;};c3_chart_internal_fn.transformMain=function(withTransition,transitions){var $$=this,xAxis,yAxis,y2Axis;if(transitions&&transitions.axisX){xAxis=transitions.axisX;}else{xAxis=$$.main.select('.'+CLASS.axisX);if(withTransition){xAxis=xAxis.transition();}}if(transitions&&transitions.axisY){yAxis=transitions.axisY;}else{yAxis=$$.main.select('.'+CLASS.axisY);if(withTransition){yAxis=yAxis.transition();}}if(transitions&&transitions.axisY2){y2Axis=transitions.axisY2;}else{y2Axis=$$.main.select('.'+CLASS.axisY2);if(withTransition){y2Axis=y2Axis.transition();}}(withTransition?$$.main.transition():$$.main).attr("transform",$$.getTranslate('main'));xAxis.attr("transform",$$.getTranslate('x'));yAxis.attr("transform",$$.getTranslate('y'));y2Axis.attr("transform",$$.getTranslate('y2'));$$.main.select('.'+CLASS.chartArcs).attr("transform",$$.getTranslate('arc'));};c3_chart_internal_fn.transformAll=function(withTransition,transitions){var $$=this;$$.transformMain(withTransition,transitions);if($$.config.subchart_show){$$.transformContext(withTransition,transitions);}if($$.legend){$$.transformLegend(withTransition);}};c3_chart_internal_fn.updateSvgSize=function(){var $$=this,brush=$$.svg.select(".c3-brush .background");$$.svg.attr('width',$$.currentWidth).attr('height',$$.currentHeight);$$.svg.selectAll(['#'+$$.clipId,'#'+$$.clipIdForGrid]).select('rect').attr('width',$$.width).attr('height',$$.height);$$.svg.select('#'+$$.clipIdForXAxis).select('rect').attr('x',$$.getXAxisClipX.bind($$)).attr('y',$$.getXAxisClipY.bind($$)).attr('width',$$.getXAxisClipWidth.bind($$)).attr('height',$$.getXAxisClipHeight.bind($$));$$.svg.select('#'+$$.clipIdForYAxis).select('rect').attr('x',$$.getYAxisClipX.bind($$)).attr('y',$$.getYAxisClipY.bind($$)).attr('width',$$.getYAxisClipWidth.bind($$)).attr('height',$$.getYAxisClipHeight.bind($$));$$.svg.select('#'+$$.clipIdForSubchart).select('rect').attr('width',$$.width).attr('height',brush.size()?brush.attr('height'):0);$$.svg.select('.'+CLASS.zoomRect).attr('width',$$.width).attr('height',$$.height);// MEMO: parent div's height will be bigger than svg when $$.selectChart.style('max-height',$$.currentHeight+"px");};c3_chart_internal_fn.updateDimension=function(withoutAxis){var $$=this;if(!withoutAxis){if($$.config.axis_rotated){$$.axes.x.call($$.xAxis);$$.axes.subx.call($$.subXAxis);}else{$$.axes.y.call($$.yAxis);$$.axes.y2.call($$.y2Axis);}}$$.updateSizes();$$.updateScales();$$.updateSvgSize();$$.transformAll(false);};c3_chart_internal_fn.observeInserted=function(selection){var $$=this,observer;if(typeof MutationObserver==='undefined'){window.console.error("MutationObserver not defined.");return;}observer=new MutationObserver(function(mutations){mutations.forEach(function(mutation){if(mutation.type==='childList'&&mutation.previousSibling){observer.disconnect();// need to wait for completion of load because size calculation requires the actual sizes determined after that completion $$.intervalForObserveInserted=window.setInterval(function(){// parentNode will NOT be null when completed if(selection.node().parentNode){window.clearInterval($$.intervalForObserveInserted);$$.updateDimension();if($$.brush){$$.brush.update();}$$.config.oninit.call($$);$$.redraw({withTransform:true,withUpdateXDomain:true,withUpdateOrgXDomain:true,withTransition:false,withTransitionForTransform:false,withLegend:true});selection.transition().style('opacity',1);}},10);}});});observer.observe(selection.node(),{attributes:true,childList:true,characterData:true});};c3_chart_internal_fn.bindResize=function(){var $$=this,config=$$.config;$$.resizeFunction=$$.generateResize();$$.resizeFunction.add(function(){config.onresize.call($$);});if(config.resize_auto){$$.resizeFunction.add(function(){if($$.resizeTimeout!==undefined){window.clearTimeout($$.resizeTimeout);}$$.resizeTimeout=window.setTimeout(function(){delete $$.resizeTimeout;$$.api.flush();},100);});}$$.resizeFunction.add(function(){config.onresized.call($$);});if(window.attachEvent){window.attachEvent('onresize',$$.resizeFunction);}else if(window.addEventListener){window.addEventListener('resize',$$.resizeFunction,false);}else{// fallback to this, if this is a very old browser var wrapper=window.onresize;if(!wrapper){// create a wrapper that will call all charts wrapper=$$.generateResize();}else if(!wrapper.add||!wrapper.remove){// there is already a handler registered, make sure we call it too wrapper=$$.generateResize();wrapper.add(window.onresize);}// add this graph to the wrapper, we will be removed if the user calls destroy wrapper.add($$.resizeFunction);window.onresize=wrapper;}};c3_chart_internal_fn.generateResize=function(){var resizeFunctions=[];function callResizeFunctions(){resizeFunctions.forEach(function(f){f();});}callResizeFunctions.add=function(f){resizeFunctions.push(f);};callResizeFunctions.remove=function(f){for(var i=0;i